Use Relative layouts, draw 9 images. And for high quality apps you may create different different layout XMLS for all 4 screen sizes.
Use “wrap_content” and “match_parent” To ensure that your layout is flexible and adapts to different screen sizes, you should use "wrap_content" and "match_parent" for the width and height of some view components.
You have to create Different values folder for different screens . Like
values-sw720dp 10.1” tablet 1280x800 mdpi
values-sw600dp 7.0” tablet 1024x600 mdpi
values-sw480dp 5.4” 480x854 mdpi
values-sw480dp 5.1” 480x800 mdpi
values-xxhdpi 5.5" 1080x1920 xxhdpi
values-xxxhdpi 5.5" 1440x2560 xxxhdpi
values-xhdpi 4.7” 1280x720 xhdpi
values-xhdpi 4.65” 720x1280 xhdpi
values-hdpi 4.0” 480x800 hdpi
values-hdpi 3.7” 480x854 hdpi
values-mdpi 3.2” 320x480 mdpi
values-ldpi 3.4” 240x432 ldpi
values-ldpi 3.3” 240x400 ldpi
values-ldpi 2.7” 240x320 ldpi
For more information you may visit here
Different values folders in android
http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html
Edited By @humblerookie
You can make use of Android Studio plugin called Dimenify to auto generate dimension values for other pixel buckets based on custom scale factors. Its still in beta, be sure to notify any issues/suggestions you come across to the developer.
Although making a different layout for different screen sizes is theoretically a good idea, it can get very difficult to accommodate for all screen dimensions, and pixel densities. Having over 20+ different dimens.xml
files as suggested in the above answers, is not easy to manage at all.
How To Use:
To use sdp
:
implementation 'com.intuit.sdp:sdp-android:1.0.5'
in your build.gradle
,Replace any dp
value such as 50dp
with a @dimen/50_sdp
like so:
<TextView
android:layout_width="@dimen/_50sdp"
android:layout_height="@dimen/_50sdp"
android:text="Hello World!" />
How It Works:
sdp
scales with the screen size because it is essentially a huge list of different dimens.xml
for every possible dp
value.
See It In Action:
Here it is on three devices with widely differing screen dimensions, and densities:
Note that the sdp
size unit calculation includes some approximation due to some performance and usability constraints.
we want to see the changes of required view size in different screens.
We need to create a different values folders for different screens and put dimens.xml file based on screen densities.
I have taken one TextView and observed the changes when i changed dimens.xml in different values folders.
Please follow the process
The below devices can change the sizes of screens when we change the normal - xhdpi \ dimens.xml
nexus 5X ( 5.2" * 1080 * 1920 : 420dpi )
nexus 6P ( 5.7" * 1440 * 2560 : 560dpi)
nexus 6 ( 6.0" * 1440 * 2560 : 560dpi)
nexus 5 (5.0", 1080 1920 : xxhdpi)
nexus 4 (4.7", 768 * 1280 : xhdpi)
Galaxy nexus (4.7", 720 * 1280 : xhdpi)
4.65" 720p ( 720 * 1280 : xhdpi )
4.7" WXGA ( 1280 * 720 : Xhdpi )
The below devices can change the sizes of screens when we change the Xlarge - xhdpi \ dimens.xml
nexus 9 ( 8.9", 2048 * 1556 : xhdpi)
nexus 10 (10.1", 2560 * 1600 : xhdpi)
The below devices can change the sizes of screens when we change the large - xhdpi \ dimens.xml
nexus 7 ( 7.0", 1200 * 1920: xhdpi)
nexus 7 (2012) (7.0", 800 * 1280 : tvdpi)
The below devices can change the sizes of screens when we change the large - mdpi \ dimens.xml
5.1" WVGA ( 480 * 800 : mdpi )
5.4" FWVGA ( 480 * 854 : mdpi )
7.0" WSVGA (Tablet) ( 1024 * 600 : mdpi )
The below devices can change the sizes of screens when we change the normal - hdpi \ dimens.xml
nexus s ( 4.0", 480 * 800 : hdpi )
nexus one ( 3.7", 480 * 800: hdpi)
The below devices can change the sizes of screens when we change the small - ldpi \ dimens.xml
2.7" QVGA Slider ( 240 * 320 : ldpi )
2.7" QVGA ( 240 * 320 : ldpi )
The below devices can change the sizes of screens when we change the xlarge - mdpi \ dimens.xml
10.1" WXGA ( tABLET) ( 1280 * 800 : MDPI )
The below devices can change the sizes of screens when we change the normal - ldpi \ dimens.xml
3.3" WQVGA ( 240 * 400 : LDPI )
3.4" WQVGA ( 240 * 432 : LDPI )
The below devices can change the sizes of screens when we change the normal - hdpi \ dimens.xml
4.0" WVGA ( 480 * 800 : hdpi )
3.7" WVGA ( 480 * 800 : hdpi )
3.7" FWVGA Slider ( 480 * 854 : hdpi )
The below devices can change the sizes of screens when we change the normal - mdpi \ dimens.xml
3.2" HVGA Slider ( ADP1 ) ( 320 * 480 : MDPI )
3.2" QVGA ( ADP2 ) ( 320 * 480 : MDPI )
There are nice libraries which will handle everything and reduce your pain. For using it, just add two dependencies in gradle:
implementation 'com.intuit.ssp:ssp-android:1.0.5'
implementation 'com.intuit.sdp:sdp-android:1.0.5'
After that, use dimens
like this:
android:layout_marginTop="@dimen/_80sdp"
You have to create a different values
folder for different screens and put dimens.xml
file according to densities.
1) values
2) values-hdpi (320x480 ,480x800)
3) values-large-hdpi (600x1024)
4) values-xlarge (720x1280 ,768x1280 ,800x1280 ,Nexus7 ,Nexus10)
5) values-sw480dp (5.1' WVGA screen)
6) values-xhdpi (Nexus4 , Galaxy Nexus)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With