2012-05-14 64 views
0

我已经在android中创建了一个应用程序,但是当我在不同屏幕尺寸上测试我的应用程序时,Android手机的外观和感觉并不稳定。在Android的屏幕尺寸

我的问题是如何设置你的应用程序显示所有Android手机?

+1

此问题已在SO上多次回答。我想我昨天回答了一次。 这是你想要的:[支持多屏幕](https://developer.android.com/guide/practices/screens_support.html)。另外,使用谷歌。 – keyser

+0

使用不同的drawable。不要硬布线。使用相对布局................. –

+0

k,padma我首先在三星Galaxy y手机上测试我的应用程序,它工作正常,但是当我在三星标签上尝试时,看起来不那么好,我想提供全局访问我的应用程序,以便每个Android可以使用它在相同的外观,我想从我的应用程序中删除屏幕大小依赖项? – user1227605

回答

2
Android has included support for three screen-size “buckets” since 1.6, 
based on these “dp” units: “normal” is currently the most popular device format (originally 320x480, more recently higher-density 480x800); 
“small” is for smaller screens, and “large” is for “substantially larger” screens. 
Devices that fall in the “large” bucket include the Dell Streak and original 7” Samsung Galaxy Tab. 
Android 2.3 introduced a new bucket size “xlarge”, in preparation for the approximately-10” tablets (such as the Motorola Xoom) that Android 3.0 was designed to support. 

xlarge screens are at least 960dp x 720dp. 

large screens are at least 640dp x 480dp. 

normal screens are at least 470dp x 320dp. 

small screens are at least 426dp x 320dp. 
(Android does not currently support screens smaller than this.) 
+0

它的好,但如何在单个应用程序中定义这些权限,所以每个Android手机都可以使用我的应用,无论是他们的屏幕大小,小,大,正常和xlarge,请通过代码显示。 – user1227605

0

最好的办法是使用相对布局,而不是像layout_height =“20dp”硬编码值 或者使用两种类型的布局各1个景观&肖像,这应该解决的问题,您鲆。但是还有另一种方式,通过动态设置视图属性来获得每个屏幕的完全相同的...这是

DisplayMetrics metrics = new DisplayMetrics(); getWindowManager()。getDefaultDisplay()。getMetrics(metrics);

int height = metrics.heightPixels; 
    int width = metrics.widthPixels; 

    Button Button1 = (Button) findViewById(R.id.button1); 
    Button Button2 = (Button) findViewById(R.id.button2); 
    Button1.setWidth(width/2); 
    Button2.setWidth(width/2);