屏幕适配三 (使用)

支持多种屏幕的目标是创建一款在 Android 系统支持的通用屏幕尺寸上都可以 正常运行且显示良好的应用。

使用“wrap_content”和“match_parent”

为确保您的布局能够灵活地适应不同的屏幕尺寸,您应该为某些视图组件的宽度和高度使用 “wrap_content” 和 “match_parent”。 如果您使用 “wrap_content”,视图的宽度或高度将设置为使内容适应该视图所需的最小尺寸,而 “match_parent” 会使组件通过扩展来匹配其父视图的尺寸。

使用尺寸限定符

res/layout/main.xml
res/layout-large/main.xml (在屏幕归类为大屏幕的设备,低于 3.2 版本)
res/layout-sw600dp/main.xml (最小宽度大于或等于 600dp 的设备,高于 3.2 版本)

使用布局别名

res/layout/main.xml,单窗格布局
res/layout/main_twopanes.xml,双窗格布局

使用屏幕方向限定符

res/values/layouts.xml:

<resources>
<item name="main_layout" type="layout">@layout/onepane_with_bar</item>
<bool name="has_two_panes">false</bool>

res/values-sw600dp-land/layouts.xml:

<resources>
<item name="main_layout" type="layout">@layout/twopanes</item>
<bool name="has_two_panes">true</bool>

res/values-sw600dp-port/layouts.xml:

<resources>
<item name="main_layout" type="layout">@layout/onepane</item>
<bool name="has_two_panes">false</bool>

使用九宫格位图

支持不同屏幕尺寸通常意味着您的图像资源也必须能够适应不同的尺寸。
例如,按钮背景必须能够适应其所应用到的任何一种按钮形状

猜你喜欢

转载自blog.csdn.net/qq_31130725/article/details/81101759
今日推荐