不同的布局不同尺寸的屏幕在Android? [英] Different Layouts For Different Screen Sizes On Android?
问题描述
所以,我提出用Eclipse中使用图形化编辑器, AbsoluteLayout
,固定的像素值,等...只是坏的一般做法的应用程序。它默认为一个 3.7in屏幕
。有没有什么办法设计
A 分离的布局
每个屏幕尺寸并有计划选择了基于上述装载屏幕尺寸?
So I made an app using in Eclipse using the Graphical Editor, AbsoluteLayout
, fixed pixel values, etc... just bad practice in general. It defaulted to a 3.7in screen
. Is there any way to design
a separate layout
for each screen size and have the program choose which to load based on said screen size?
推荐答案
我通过运行这个code在启动时修复了这个
I fixed this by running this code at startup
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
从那里我做了一个if语句来检查的决议,并加载了该决议提出了具体布置。 EX。 WVGA屏幕是800×480,所以我检查了,并负载布局。
From there I do an if statement to check for resolution and load a specific layout made for that resolution. EX. WVGA screen is 800x480 so I check for that and load the layout.
if (width == 480 && height == 800)
{
setContentView(R.layout.main);
}
这是对API< 13,现在这些功能都pcated德$ P $,请参阅本如何获得屏幕尺寸
This was for API < 13, now those functions are deprecated, see this How to get screen dimensions
这篇关于不同的布局不同尺寸的屏幕在Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!