我想在 Android 中为平板电脑和手机创建不同的布局。我应该把布局资源放在哪里才能做出这种区分?
问问题
79846 次
6 回答
171
我知道这是一个老问题,但为了它......根据文档,你应该像这样创建多个资产文件夹
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)
于 2012-08-14T02:15:16.283 回答
46
如果您在代码中使用片段概念(表示多窗格布局),那么最好使用 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
于 2013-04-30T08:58:16.797 回答
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
您可以在此处找到有关可以添加到文件夹结构以区分不同设置的更多信息。
最大的问题是,Android SDK 并没有真正正式整合平板电脑。希望这将在下一个版本的 Android 中得到解决。否则,您只需要确保使用适用于任何屏幕尺寸的缩放布局。
于 2010-11-15T15:08:36.490 回答
6
根据文档,您应该像这样创建多个资产文件夹......完整列表......
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)
于 2018-03-01T06:35:49.957 回答
0
此源还提供了如何根据设备配置调用任何资源,例如:语言、屏幕宽度/高度、布局方向、屏幕方向等。
您必须小心将默认资源作为提到的来源,例如为平板电脑调用高质量的图标。
于 2015-12-02T18:36:04.337 回答