简体   繁体   中英

How to handle different screen sizes

im facing a problem with screen sizes on android. I already implemented different layouts using layout-normal, layout-large ... the problem is in layout-normal it has the coverage of 3.4 inches phones to 4.2 or more i refer to this doc

http://developer.android.com/guide/practices/screens_support.html

now im using a samsung galaxy ace with 3.5 inches everything work well, but not on my samsung s4 and the an emulator of 4.0 inches who shares the same layout. Please help me.

the probem is on layout-normal, there are severl phones who have differernt screen sizes will have diffrent output layout.

is theres a way to specify a layout for 5.1 inches, 4,0 inches ....

thank you in advance.

im not really sure if this is what you are looking for.. but you can check the screen size of the phone

 Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;
        int height = size.y;

and set it

if(width == 480 || height == 800){
            //get resource here
 } else if (width < 480 || height < 800) {
       //get resource here

this is just an example hope it helps.

Your problem tells me that you are using layouts incorrectly. The layout needs to be able to fit itself inside an approximate screen size. That is what the "normal", "large", etc. screen size buckets are for. Your layout should not take up exactly "5.1" inches, because there are so many different screen sizes, that you would have to make an overwhelming number of layouts if you took this approach.

You simply need to use RelativeLayout or LinearLayout with layout_weight on the contents, and you will be able to use the same layout with multiple slightly different screen sizes.

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