Android平板电脑的布局

hpi*_*que 70 android tablet android-layout

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

urS*_*Sus 154

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

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)
Run Code Online (Sandbox Code Playgroud)


Sak*_*iah 41

如果你在代码中使用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)
Run Code Online (Sandbox Code Playgroud)

请参阅表格以了解wdp

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


Bry*_*nny 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
Run Code Online (Sandbox Code Playgroud)

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

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


小智 5

根据文档,您应该像这样创建多个资产文件夹......完整列表......

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)
Run Code Online (Sandbox Code Playgroud)