【发布时间】:2011-05-10 06:54:54
【问题描述】:
我想在 Android 中为平板电脑和手机创建不同的布局。我应该把布局资源放在哪里才能做出这种区分?
【问题讨论】:
标签: android android-layout tablet
我想在 Android 中为平板电脑和手机创建不同的布局。我应该把布局资源放在哪里才能做出这种区分?
【问题讨论】:
标签: android android-layout tablet
对于布局,我相信您目前只能通过以下方式进行区分:
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 中得到解决。否则,您只需要确保使用适用于任何屏幕尺寸的缩放布局。
【讨论】:
我知道这是一个老问题,但为了它...... 根据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)
【讨论】:
如果您在代码中使用 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
【讨论】:
This source 还提供了如何根据设备配置调用任何资源,例如:语言、屏幕宽度/高度、布局方向、屏幕方向...等。
您必须小心将默认资源设置为提到的来源,例如为平板电脑调用高质量的图标。
【讨论】:
根据文档,您应该像这样创建多个资产文件夹......完整列表......
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)
【讨论】: