Android supporting multiple resolution with multiple layout folder
For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens.
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
Thats code in the Manifest supports all dpis.
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
Android devices with different height takes same layout folder
Well you are right in some sense android should take layout dependent on different densities but some mobile do not fall under specific density. Therefore android will pick up default layout from layout directory.
to support multiple screen resolution provide different layout for different screen sizes, you can make following directories in res directory like this
layout-hdpi
layout-mdpi
layout-xhdpi
layout-xxhdpi
layout-w320dp-h408dp
layout-w480dp-h800dp
layout-w480dp-h854dp
layout-w720dp-h1280dp
layout-w1080dp-h1920dp
when you provide layout in all this directories you will give multiple screen support for different sizes as well
layout-w1440dp-h2560dp
Use "dip" instead they will help you in debugging your layout as they will try to keep a coherent size to multiple screen resolutions,
<ImageView
android:id="@+id/avtar_animation_11"
android:layout_width="45dip"
android:layout_height="45dip"
android:src="@drawable/avtar011"/>
while supporting multiple screen when you give "dp" to dimensions, Actually android expects you to provide different values for different screen resolution. Lets say below is your imagview dimensions make few folders in res folder in your android project like these below
values-hdpi, values-mdpi, values-ldpi, values-xhdpi, values-xxhdpi
and in them make a dimens.xml
file each of them and write
<dimen name="image_view_width">28dp</dimen>
<dimen name="image_view_height">28dp</dimen>
now that i have mentioned "dp" here instead of dip android wants me to keep track for different dimensions for different screen resolution, So i will change the image_view_width and image_view_height values are in separate values folders where dimens.xml is located. Make sure your dp values change as per your screen resolution you want your view to fit in.
<ImageView
android:id="@+id/avtar_animation_11"
android:layout_width="@dimen/image_view_width"
android:layout_height="@dimen/image_view_height"
android:src="@drawable/avtar011"/>
hard part is over now android will pick one of dimens.xml values depending on which screen your app is running, Voila now your layout rocks
Related Topics
Retrieve Contact Phone Number from Uri in Android
Android: How to Get Current Opened Application Name on Screen
Display Unity Scene as Sub View in Android Studio
Batch Scripting - If Exist ./Sdcard/File.Any Using Adb
How to Get a Fragment to Remove Itself, I.E. Its Equivalent of Finish()
Format Credit Card in Edit Text in Android
Android 4.0, Text on the Action Bar Never Shows
How to Give Notifications on Android on Specific Time
Take a Screenshot Using Mediaprojection
Firebase Sort by Points Depending on Date
Cannot Resolve Mapactivity Class on Android
Mvvmcross Changing Viewmodel Within a Mvxbindablelistview
Moving or Copying Data from One Node to Another in Firebase Database
Should Accessing Sharedpreferences Be Done Off the UI Thread