How to determine the dimension.xml for each screen size in Android?

With the support of different screen sizes (densities), Android often focuses on creating different layouts for every possible screen. I.e.

  • ldpi
  • Mdpi
  • HDI
  • xhdpi
  • xxhdpi
  • xxxhdpi

I designed the layout for the xhdpi screen as a reference, and defined its dimensions in dimensions.xml . Now I want to provide support for every possible screen size. How can i do this?

As far as I know, I can use this tool to determine the correct dimensions.xml for other screen sizes and add it to my project. Is this the right way to do this in my situation?

Another question: I only need to create a dimension.xml for the above screen sizes? If so, what is w820dp ?

Thanks for your help. I need to support only phones (not tablets or other devices).

+107
android android-layout android-activity android-screen-support
Sep 30 '15 at 7:57
source share
9 answers

You need to create a folder Different values ​​for different screens . how

 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 

enter image description here

For more information you can find here.

Folders of various values ​​in android

http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html

Edited . @humblerookie

You can use the Android Studio plugin called Dimenify to automatically generate dimension values ​​for other pixel buckets based on custom scale factors. It is still in beta, be sure to report any problems / suggestions that you encounter with the developer.

+231
Sep 30 '15 at 8:21
source share

we want to see changes in the required view size on different screens.

We need to create folders with different values ​​for different screens and put a file of a diameter.xml based on the density of the screen.

I took one TextView and watched the changes when I changed the dimensions.xml to folders with different values.

Please follow the procedure

normal - xhdpi \ dens.xml

The following devices can resize screens when changing the normal - xhdpi \ dens.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)

Galactic communication (4.7 ", 720 * 1280: xhdpi)

4.65 "720p (720 * 1280: xhdpi)

4.7 "WXGA (1280 * 720: Xhdpi)

Xlarge - xhdpi \ dens.xml

The following devices can resize screens when changing Xlarge-xhdpi \ dens.xml

nexus 9 (8.9 ", 2048 * 1556: xhdpi)

nexus 10 (10.1 ", 2560 * 1600: xhdpi)

large - xhdpi \ dens.xml

The devices below can resize screens when resizing large - xhdpi \ dens.xml

nexus 7 (7.0 ", 1200 * 1920: xhdpi)

nexus 7 (2012) (7.0 ", 800 * 1280: tvdpi)

The screens below are visible in the “Search for Shared Phones and Tablets” section.

large - mdpi \ dens.xml

The following devices can resize screens when resizing large - mdpi \ dens.xml

5.1 "WVGA (480 * 800: mdpi)

5.4 "FWVGA (480 * 854: mdpi)

7.0 "WSVGA (tablet) (1024 * 600: mdpi)

normal - hdpi \ larg.xml

The following devices can resize screens when changing normal - hdpi \ dens.xml

nexus s (4.0 ", 480 * 800: hdpi)

nexus one (3.7 ", 480 * 800: hdpi)

small - ldpi \ dens.xml

The following devices can resize screens when changing a small ldpi \ dens.xml

2.7 "QVGA Slider (240 * 320: ldpi)

2.7 "QVGA (240 * 320: ldpi)

xlarge - mdpi \ dens.xml

The devices below can resize screens when changing xlarge-mdpi \ dens.xml

10.1 "WXGA (tABLET) (1280 * 800: MDPI)

normal - ldpi \ dens.xml

The devices below can resize screens when the normal one changes - ldpi \ dens.xml

3.3 "WQVGA (240 * 400: LDPI)

3.4 "WQVGA (240 * 432: LDPI)

normal - hdpi \ larg.xml

The following devices can resize screens when changing normal - hdpi \ dens.xml

4.0 "WVGA (480 * 800: hdpi)

3.7 "WVGA (480 * 800: hdpi)

3.7 "FWVGA Slider (480 * 854: hdpi)

normal - mdpi \ dens.xml

The following devices can change the size of the screens when changing the normal - mdpi \ dens.xml

3.2 "HVGA Slider (ADP1) (320 * 480: MDPI)

3.2 "QVGA (ADP2) (320 * 480: MDPI)

+24
Aug 17 '16 at 8:16
source share

Use scalable DP

Although a theoretically good idea is to create a different layout for a screen of different sizes, it can be very difficult to adapt for all screen sizes and pixel density. Having more than 20+ different dimens.xml as suggested in the answers above is not at all easy to manage.

How to use:

To use sdp :

  1. Include implementation 'com.intuit.sdp:sdp-android:1.0.5' in your build.gradle ,
  2. Replace any dp value such as 50dp with @dimen/50_sdp as follows:

     <TextView android:layout_width="@dimen/_50sdp" android:layout_height="@dimen/_50sdp" android:text="Hello World!" /> 

How does it work:

sdp scales with the size of the screen, because it is, in fact, a huge list of different dimens.xml for each possible dp value.

enter image description here

See it in action:

Here it is on three devices with widely varying screen sizes and densities:

enter image description here

Please note that sdp units of size sdp includes some approximation due to some performance limitations and usability.

+21
Aug 6 '18 at 13:48
source share

You need to create a different values folder for different screens and put the file in a file in accordance with the 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) 
+6
Sep 30 '15 at 8:15
source share

I downloaded a simple Java program that takes the location of your project and the measurement file you want to enter. Based on this, it will output the corresponding measurement file to the console. Here is a link to it:

https://github.com/akeshwar/Dimens-for-different-screens-in-Android/blob/master/Main.java

Here is the complete code for the link:

 public class Main { /** * You can change your factors here. The current factors are in accordance with the official documentation. */ private static final double LDPI_FACTOR = 0.375; private static final double MDPI_FACTOR = 0.5; private static final double HDPI_FACTOR = 0.75; private static final double XHDPI_FACTOR = 1.0; private static final double XXHDPI_FACTOR = 1.5; private static final double XXXHDPI_FACTOR = 2.0; private static double factor; public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); System.out.println("Enter the location of the project/module"); String projectPath = in.nextLine(); System.out.println("Which of the following dimension file do you want?\n1. ldpi \n2. mdpi \n3. hdpi \n4. xhdpi \n5. xxhdpi \n6. xxxhdpi"); int dimenType = in.nextInt(); switch (dimenType) { case 1: factor = LDPI_FACTOR; break; case 2: factor = MDPI_FACTOR; break; case 3: factor = HDPI_FACTOR; break; case 4: factor = XHDPI_FACTOR; break; case 5: factor = XXHDPI_FACTOR; break; case 6: factor = XXXHDPI_FACTOR; break; default: factor = 1.0; } //full path = "/home/akeshwar/android-sat-bothIncluded-notintegrated/code/tpr-5-5-9/princetonReview/src/main/res/values/dimens.xml" //location of the project or module = "/home/akeshwar/android-sat-bothIncluded-notintegrated/code/tpr-5-5-9/princetonReview/" /** * In case there is some I/O exception with the file, you can directly copy-paste the full path to the file here: */ String fullPath = projectPath + "/src/main/res/values/dimens.xml"; FileInputStream fstream = new FileInputStream(fullPath); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine; while ((strLine = br.readLine()) != null) { modifyLine(strLine); } br.close(); } private static void modifyLine(String line) { /** * Well, this is how I'm detecting if the line has some dimension value or not. */ if(line.contains("p</")) { int endIndex = line.indexOf("p</"); //since indexOf returns the first instance of the occurring string. And, the actual dimension would follow after the first ">" in the screen int begIndex = line.indexOf(">"); String prefix = line.substring(0, begIndex+1); String root = line.substring(begIndex+1, endIndex-1); String suffix = line.substring(endIndex-1,line.length()); /** * Now, we have the root. We can use it to create different dimensions. Root is simply the dimension number. */ double dimens = Double.parseDouble(root); dimens = dimens*factor*1000; dimens = (double)((int)dimens); dimens = dimens/1000; root = dimens + ""; System.out.println(prefix + " " + root + " " + suffix ); } System.out.println(line); } } 
+6
May 25 '16 at 7:07 a.m.
source share

You can put a dimens.xml in

1) values

2) hdpi values

3) xhdpi values

4) xxhdpi values

And indicate the different sizes in the dimens.xml in the appropriate folders according to the densities.

+4
Sep 30 '15 at 8:07
source share

If you want to see more: here is a link for a list of devices (tablet, mobile, clock), including watch , chromebook , windows and mac . Here you can find the density, size, etc. Just based on this, this is a good resource if you use an emulator too.

If you click on a specific item, it will display more detailed information on the right side. sample

Since this is Android , I will post related to it. sample1

sample2

~ Better if you save a copy of the Internet. To view it offline.

+1
Oct. 06 '16 at 5:47
source share

There are good libraries that can handle everything and reduce your pain. To use 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 the dimens :

  android:layout_marginTop="@dimen/_80sdp" 
+1
Mar 07 '19 at 14:24
source share

Android 3.2 introduces a new approach to screen sizes, numbers describing the screen size are in units of "dp". Can we use

smallest width dp: the smallest width available for the application layout in units of "dp"; this is the smallest dp width you will ever encounter with any rotation of the display.

To create a single right click on res →> new →> Android Resource Directory

From Available Qualifiers, move the Smallest Screen Width window to Selected Qualifiers

In the Screen Width window , simply write the value "dp", starting with you, if Android Studio used this size.

How the Project view changes, right-click the new resource directory

new →> Values ​​Resource File, enter a new name for the file of the diameter.xml , and you 're done.

0
Dec 23 '17 at 13:34 on
source share



All Articles