2

I have made this very simple calculator layout. But its different for 480 DPI and 420 DPI on my phone. There is free space on right part of screen in 420DPI and buttons are thinner than 480DPI. I used dp as a units of measurements for buttons and sp for text.

I read Supporting Different Screen Sizes | Android Developers but couldn't really solve my problem.

I have read that dp unit is independent of DPI of the screen and buttons will scale up or down dynamically. Then how come my buttons get thinner on different DPI even after i used dp as an unit?

dhh
  • 4,289
  • 8
  • 42
  • 59
Faraz Ahmed
  • 153
  • 11

2 Answers2

5

I put a file in res folder, the file name is values-w410dp ,because Nexus 5X 1920 x 1080 px (730 x 410 dp) normal 420 dpi.

You can try. It can control layout.

minus_one
  • 62
  • 1
  • 3
1

You need to have multiple layout folders in res. Name one of them layout-xxhdpi and put your layout xml there. Devices with density >= 480dpi will load layouts from this folder. Another layout folder should be named layout. Devices with density lower than 480dpi will load layouts from layout. In order to support multiple screens, layouts must have same ID in both folders. You can read more about resource qualifiers here http://developer.android.com/guide/topics/resources/providing-resources.html

callOfCode
  • 893
  • 8
  • 11
  • I already tried this. App loads layout from xxhdpi folder in case of 480 DPI as well as in 420 DPI. It do not use xml from layout folder in case of 420 DPI as you said – Faraz Ahmed Jul 06 '15 at 08:01
  • I tried this also , layout-xxhdpi folder but still both densities the same layuot used. – david Oct 31 '17 at 04:37