用于手机的Andr​​oid有条件的布局:片 [英] Android conditional layouts for phones:tablets

查看:146
本文介绍了用于手机的Andr​​oid有条件的布局:片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个应用程序,是现成的,主要用于手机上,但会方便在平板电脑上如果有使用。

I am making an app that is readily available and MOSTLY used on phones, but would be CONVENIENT to use on a tablet if available.

我所熟悉的横向/纵向布局为单独的XML文件,但如何在不同的分辨率?这也是一个问题仅限电话应用程序,什么是有可扩展性布局的最好办法。

I am familiar with landscape/portrait layouts for the separate XML files, but what about for the different resolutions? This is also an issue for phone-only applications, what is the best way to have scalable layouts.

我用的是这是密度独立的,但效果不如只用百分比,这将有效地扩展您的布局值。

I use the dip values which are density independent but not as effective as just using percentages that will scale your layout effectively.

c中的XML我也很难$ C $。我想,我可以以编程方式产生,通过检查屏幕宽度和高度上的每一个活动的布局,但告诉我有更好的办法吗?

I also hardcode the XML. I IMAGINE that I could programmatically generate the layout by checking the screen width and height ON EVERY ACTIVITY, but tell me there is a better way?

推荐答案

您可以在您指定的布局纵向或横向以同样的方式指定的屏幕尺寸(小,中,大和XLARGE)provive额外的布局。

You can provive extra layouts by specifying the screen size (small, normal, large and xlarge) in the same way you specify layouts for portrait or landscape.

这些都是从与本主题的 Android的文档采取了一些例子

These are some examples taken from the android documentation related to this subject

res/layout/my_layout.xml             // layout for normal screen size ("default")
res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

这本书的忙codeR指南Android开发有关于这个主题的一个很好的解释。

The book The Busy Coder's Guide to Android Development has an excellent explanation about this subject.

这篇关于用于手机的Andr​​oid有条件的布局:片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆