我想在Android中为平板电脑和手机创建不同的布局。为了实现这种区分,我应该将布局资源放在哪里?
我知道这是一个旧问题,但为了完整性起见... 根据文档,您应该创建多个资源文件夹,如下所示。
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)
如果您在代码中使用片段概念(表示多窗格布局),则最好使用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
表2.屏幕尺寸的新配置限定符(引入于Android 3.2)。
在以下链接中查看
http://developer.android.com/guide/practices/screens_support.html
我认为使用布局时,您只能通过以下方式进行区分:
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版本中得到解决。否则,您只需要确保使用适用于任何屏幕尺寸的缩放布局。
根据文档,你应该创建多个资产文件夹,如下所示..完整列表...
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)
这个资源还提供了如何根据设备配置调用任何资源的方法,比如:语言、屏幕宽度/高度、布局方向、屏幕方向等等。
你需要小心地将默认资源设置为所提到的源,比如为平板电脑调用高质量的图标。