簡體   English   中英

Android 中的平板電腦布局

[英]Layout for tablets in Android

我想為 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)

如果您在代碼中使用 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

對於布局,我相信您目前只能通過以下方式進行區分:

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)

Android Studio 中的“預覽方向”下拉菜單如下所示,可以幫助生成快速的橫向和平板電腦布局 xml。 它還為這些布局變體創建單獨的文件夾,即layout-landlayout-sw600dp ,並將布局 xmls 放置在這些文件夾中。 在此處輸入圖片說明

該源還提供了如何根據設備配置調用任何資源,例如:語言、屏幕寬度/高度、布局方向、屏幕方向...等。

您必須小心地按照來源設置默認資源,例如為平板電腦調用高質量的圖標。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM