Android平板电脑的布局

问题描述 投票:67回答:5

我想在Android中为平板电脑和手机创建不同的布局。我应该在哪里放置布局资源以实现这种差异化?

android android-layout tablet
5个回答
147
投票

我知道这是一个老问题,但为了它...根据documentation,你应该创建像这样的多个资产文件夹

res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml   # For 10” tablets (720dp wide and bigger)

39
投票

如果你在代码中使用Fragment概念(意味着多窗格布局)那么最好使用wdp而不是swdp

res/layout-w600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
res/layout-w720dp/main_activity.xml   # For 10” tablets (720dp wide and bigger)
res/layout-w600dp-land/main_activity.xml   # For 7” tablets in landscape (600dp wide and                  bigger)
res/layout-w720dp-land/main_activity.xml   # For 10” tablets in landscape (720dp wide and bigger)

请参阅表格以了解wdp

Table 2. New configuration qualifers for screen size (introduced in Android 3.2).在以下链接http://developer.android.com/guide/practices/screens_support.html


23
投票

对于布局,我相信您目前只能通过以下方式进行区分:

res/layout/my_layout.xml            // layout for normal screen size
res/layout-small/my_layout.xml      // layout for small screen size
res/layout-large/my_layout.xml      // layout for large screen size
res/layout-large-land/my_layout.xml // layout for large screen size in landscape mode

您可以找到有关可以添加到文件夹结构的更多信息,以区分不同的设置here

最大的问题是Android SDK还没有正式合并平板电脑。希望这将在下一个版本的Android中得到解决。否则,您只需确保使用适用于任何屏幕大小的缩放布局。


2
投票

根据文档,您应该创建多个资产文件夹,例如this..full list ...... qazxsw poi


0
投票

res/layout/main_activity.xml // For handsets (smaller than 600dp available width) res/layout/main_activity.xml // For handsets (smaller than 600dp available width) res/layout-sw600dp/main_activity.xml // For 7” tablets (600dp wide and bigger) res/layout-sw720dp/main_activity.xml // For 10” tablets (720dp wide and bigger) res/layout-sw600dp-land/main_activity.xml // For 7” tablets in landscape (600dp wide and bigger) res/layout-sw720dp-land/main_activity.xml // For 10” tablets in landscape (720dp wide and bigger)还提供了如何根据设备配置调用任何资源,如:语言,屏幕宽度/高度,布局方向,屏幕方向等。

您需要小心将默认资源作为提到的来源,例如为平板电脑调用高质量的图标。

© www.soinside.com 2019 - 2024. All rights reserved.