android studio sizing issue
android dpi sizes
supporting different screen sizes in android example
android image size for different screens
how to set android layout to support all screen sizes
how to auto resize, compatible, adjust screen size for all android devices
android get screen size in dp
android screen size
I have buttons in my activity they are in correct size in editor but when i install my app on my device sizes are not correct.
Screenshots
Editor
Device
Code
xml file
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg2" tools:context=".MainActivity"> <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:theme="@style/ThemeOverlay.AppCompat.ActionBar" app:titleTextColor="@color/White" /> <LinearLayout android:id="@+id/itemButtons" android:layout_width="match_parent" android:layout_height="326dp" android:layout_alignTop="@+id/toolbar" android:layout_alignBottom="@+id/adView" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="60dp" android:layout_marginBottom="405dp" android:gravity="center" android:orientation="vertical"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="15dp" android:layout_marginEnd="4sp" android:gravity="center" android:orientation="horizontal" android:weightSum="2"> <Button android:id="@+id/button" android:layout_width="151dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginEnd="4dp" android:background="#76FF03" android:text="@string/alphabetButton" android:textColor="#000000" /> <Button android:id="@+id/button2" android:layout_width="151dp" android:layout_height="wrap_content" android:layout_gravity="center" android:background="#2196F3" android:text="@string/numberButton" android:textColor="#000000" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="15dp" android:layout_marginTop="7dp" android:layout_marginEnd="4sp" android:gravity="center" android:orientation="horizontal" android:weightSum="2"> <Button android:id="@+id/button3" android:layout_width="151dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginEnd="4dp" android:background="#651FFF" android:text="@string/colorsButton" android:textColor="#000000" /> <Button android:id="@+id/button4" android:layout_width="151dp" android:layout_height="wrap_content" android:layout_gravity="center" android:background="#FFEA00" android:text="@string/shapes" android:textColor="#000000" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="15dp" android:layout_marginTop="7dp" android:layout_marginEnd="4sp" android:gravity="center" android:orientation="horizontal" android:weightSum="2"> <Button android:id="@+id/button5" android:layout_width="151dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginEnd="4dp" android:background="#FF5252" android:text="@string/bodyParts" android:textColor="#000000" /> <Button android:id="@+id/button6" android:layout_width="151dp" android:layout_height="wrap_content" android:layout_gravity="center" android:background="#C6FF00" android:text="@string/furnitures" android:textColor="#000000" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="15dp" android:layout_marginTop="7dp" android:layout_marginEnd="4sp" android:gravity="center" android:orientation="horizontal" android:weightSum="2"> <Button android:id="@+id/button7" android:layout_width="151dp" android:layout_height="wrap_content" android:layout_gravity="center" android:background="#1DE9B6" android:text="@string/cityParts" android:textColor="#000000" /> </LinearLayout> </LinearLayout> </RelativeLayout>
Any idea?
Solution 1
you can achieve this by giving margin to your main LinearLayout
as below
add android:layout_marginStart="30dp"
and android:layout_marginEnd="30dp"
and set values according to your need
<LinearLayout android:id="@+id/itemButtons" android:layout_width="match_parent" android:layout_height="326dp" android:layout_alignTop="@+id/toolbar" android:layout_alignBottom="@+id/adView" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="60dp" android:layout_marginBottom="405dp" android:gravity="center" android:layout_marginStart="30dp" //margin start android:layout_marginEnd="30dp" //margin end change value as your need android:orientation="vertical"> ... </LinearLayout>
Solution 2
for making responsive as your requirment you can use android:weightSum="1"
as below.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <androidx.appcompat.widget.Toolbar /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg2" android:layout_gravity="center" android:gravity="center" android:weightSum="1"> <LinearLayout android:id="@+id/itemButtons" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight=".8" android:gravity="center" android:orientation="vertical"> .... </LinearLayout> </LinearLayout>
Support different pixel densities, 48x48 (1.0x baseline) for medium-density (mdpi) 72x72 (1.5x) for high-density (hdpi) 96x96 (2.0x) for extra-high-density (xhdpi) 144x144 (3.0x) for extra-extra-high-density (xxhdpi) Checking for adequate disk space. To avoid crashes and hangs caused by not having enough free disk space, the emulator checks for sufficient free disk space on startup, and will not start unless at least 2 GB is free. If the emulator fails to start for you, check to see that you have adequate free disk space.
You are giving fix sizes to buttons, give weight to buttons and set the width to zero it will be responsive
<Button android:id="@+id/button7" android:layout_width="0dp" android:layout_weight="1"/>
getting the screen density programmatically in android?, Android runs on a variety of devices that have different screen sizes and pixel densities. The system performs basic scaling and resizing to Upgrading the Platform Tools to 29.0.4 or higher fixes both issues. To upgrade the Platform Tools, do the following: Open the SDK Manager from Android Studio by clicking Tools > SDK Manager or click SDK Manager in the toolbar. Click the checkbox next to Android SDK Platform-Tools so it shows a checkmark.
my view you give first three row in button width="0dp" and give weight="1".button divided in 2 part.
Screen compatibility overview, Solution 1 you can achieve this by giving margin to your main LinearLayout as below add android:layout_marginStart="30dp" and APK Analyzer Find opportunities to reduce your Android app size by inspecting the contents of your app APK file, even if it wasn't built with Android Studio. Inspect the manifest file, resources, and DEX files. Compare two APKs to see how your app size changed between app versions.
android studio sizing issue, The ImageView handles all the loading and scaling of the image for you. Note the scaleType attribute which defines how the images will be scaled to fit in your Click File > Settings (on macOS, Android Studio > Preferences) to open the Settings dialog. In the left pane, expand the Editor section and click Inspections. Click the checkboxes to select or deselect lint checks as appropriate for your project. Click Apply or OK to save your changes.
Working with the ImageView, But if we specify the size of a View in pixels, there's a very big problem which will arise since every device has a different pixel screen ratio. The more the number Android version: 10; Describe the bug When scrcpy is sent to Split Screen on macOS (for eg: with Android Studio), resizing the split does not resize the content but only extends the black border and sometimes just exits out of split screen mode
How to scale different Views to all screen sizes in Android Studio , I'm so lucky I found this video I've been having problems with my layout and it totally Duration: 5:49 Posted: Mar 28, 2016 The misleading ERROR: resizing partition e2fsck failed with exit code 8 when starting an Android Virtual Device (AVD) can occur when you have an old version of Android SDK installed, but without the Android Studio.
Comments
- but would that be responsive due to devices screen size? you know it's fixed margin.
- try solution 2 for responsive on every screen @mafortis