简体   繁体   中英

Calculator app different layout on same screen size but different DPI (420 DPI vs 480 DPI)

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM