简体   繁体   English

如何处理不同的屏幕尺寸

[英]How to handle different screen sizes

im facing a problem with screen sizes on android. 即时通讯在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 我已经使用layout-normal,layout-large实现了不同的布局......问题在于布局 - 正常它有3.4英寸手机到4.2或更多的覆盖率我参考这个doc

http://developer.android.com/guide/practices/screens_support.html 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. 现在我使用3.5英寸的三星Galaxy ace一切正常,但不是我的三星s4和4.0英寸的共享相同布局的模拟器。 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 .... 是一种指定5.1英寸,4.0英寸的布局....

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. 你的布局不应该占用“5.1”英寸,因为有很多不同的屏幕尺寸,如果采用这种方法,你必须制作大量的布局。

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. 您只需要对内容使用RelativeLayoutLinearLayout和layout_weight,您就可以使用相同的布局,屏幕尺寸略有不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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