Android 中平板电脑的布局

发布于 2024-10-02 03:57:17 字数 58 浏览 1 评论 0原文

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

I would like to create different layouts for tablets and handsets in Android. Where should I put the layout resources in order to make this differentiation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

深府石板幽径 2024-10-09 03:57:17

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

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)

I know this is an old question, but for the sake of it...
According documentation, you should create mutiple asset folders like this

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)
终陌 2024-10-09 03:57:17

如果您在代码中使用片段概念(意味着多窗格布局),那么最好使用 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

If you are using Fragment concept in the code(means Multi-Pane layout) then its best to use wdp instead of 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)

Refer the table for understanding wdp

Table 2. New configuration qualifers for screen size (introduced in Android 3.2).
In the following link
http://developer.android.com/guide/practices/screens_support.html

无畏 2024-10-09 03:57:17

对于布局,我相信您当前只能通过以下方式进行区分:

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 的下一个版本中得到解决。否则,您只需确保使用适用于任何屏幕尺寸的缩放布局即可。

With layouts, I believe you can only current differentiate by the following:

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

You can find more info on what you can add to the folder structure to differentiate between different settings here.

The biggest problem is that the Android SDK hasn't really incorporated tablets officially. Hopefully that will be resolved in the next version of Android. Otherwise, you just need to make sure you use scaling layouts that will work for any screen size.

摘星┃星的人 2024-10-09 03:57:17

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

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)

According documentation, you should create mutiple asset folders like this..full list......

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)
[浮城] 2024-10-09 03:57:17

Android Studio 中的“预览方向”下拉菜单(如下所示)可以帮助生成快速横向和平板电脑布局 xml。它还为这些布局变体创建单独的文件夹,即 layout-landlayout-sw600dp,并将布局 xml 放置在这些文件夹中。
输入图片此处描述

"Orientation for preview" dropdown in Android Studio as shown below can help generate quick landscape and tablet layout xmls. It also creates separate folders i.e. layout-land and layout-sw600dp for these layout variations and place the layout xmls within these folders.
enter image description here

零度° 2024-10-09 03:57:17

此源还提供了如何根据设备配置调用任何资源,如:语言、屏幕宽度/高度、布局方向、屏幕方向等。

您必须小心地创建默认资源,如提到的来源,例如为平板电脑调用高质量的图标。

This source also providing how to call any resources based on device configurations, like: language, screen width/height, layout direction, screen orientation...etc.

You've to be careful to make a default resource as the source mentioned, like calling high quality of icons for tablets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文