For simplicity, Android groups all actual screen sizes into four generalized sizes: small, normal, large, and extra-large.
For simplicity, Android groups all actual screen densities into six generalized densities: low, medium, high, extra-high, extra-extra-high, and extra-extra-extra-high.
- ldpi (low) ~120dpi
- mdpi (medium) ~160dpi
- hdpi (high) ~240dpi
- xhdpi (extra-high) ~320dpi
- xxhdpi (extra-extra-high) ~480dpi
- xxxhdpi (extra-extra-extra-high) ~640dpi
- 36x36 (0.75x) for low-density
- 48x48 (1.0x baseline) for medium-density
- 72x72 (1.5x) for high-density
- 96x96 (2.0x) for extra-high-density
- 144x144 (3.0x) for extra-extra-high-density
- 192x192 (4.0x) for extra-extra-extra-high-density (launcher icon only; see note above)
Table 1. Configuration qualifiers that allow you to provide special resources for different screen configurations.
Screen characteristic | Qualifier | Description |
Size | small | Resources for small size screens. |
normal | Resources for normal size screens. (This is the baseline size.) | |
large | Resources for large size screens. | |
xlarge | Resources for extra-large size screens. | |
Density | ldpi | Resources for low-density (ldpi) screens (~120dpi). |
mdpi | Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.) | |
hdpi | Resources for high-density (hdpi) screens (~240dpi). | |
xhdpi | Resources for extra-high-density (xhdpi) screens (~320dpi). | |
xxhdpi | Resources for extra-extra-high-density (xxhdpi) screens (~480dpi). | |
xxxhdpi | Resources for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi). Use this for the launcher icon only, see noteabove. | |
Orientation | land | Resources for screens in the landscape orientation (wide aspect ratio). |
port | Resources for screens in the portrait orientation (tall aspect ratio). |
Table 2. New configuration qualifiers for screen size (introduced in Android 3.2).
比如Table3, 1280X800, sw=800, w=1280, h=800
Table 3. Various screen configurations available from emulator skins in the Android SDK (indicated in bold) and other representative resolutions.
Low density (120), ldpi | Medium density (160), mdpi | High density (240), hdpi | Extra-high-density (320), xhdpi | |
---|---|---|---|---|
Small screen | QVGA (240x320) | 480x640 | ||
Normal screen | WQVGA400 (240x400) WQVGA432 (240x432) | HVGA (320x480) | WVGA800 (480x800) WVGA854 (480x854) 600x1024 | 640x960 |
Large screen | WVGA800** (480x800) WVGA854** (480x854) | WVGA800* (480x800) WVGA854* (480x854) 600x1024 | ||
Extra-Large screen | 1024x600 | WXGA (1280x800)† 1024x768 1280x768 | 1536x1152 1920x1152 1920x1200 | 2048x1536 2560x1536 2560x1600 |
* To emulate this configuration, specify a custom density of 160 when creating an AVD that uses a WVGA800 or WVGA854 skin. ** To emulate this configuration, specify a custom density of 120 when creating an AVD that uses a WVGA800 or WVGA854 skin. † This skin is available with the Android 3.0 platform |
values-ldpi 2.7” 240x320 ldpi
可以使用下面的代码来测试sw为多少
Configuration config = getResources().getConfiguration();
int smallestScreenWidth = config.smallestScreenWidthDp;
Log.d("jack", "smallest width="+smallestScreenWidth);
HUAWEI C8816D | 5英寸960x540像素 | 360 |
Nexus 7 | 7英寸800*1280像素 | 800 |
Google Nexus 10 | 10英寸2560x1600像素 | 800 |
在平板的开发中有一个问题, 在清单文件中设置横竖屏转动不会重启Activity, Activity分为俩块Fragment, 横屏时左右比为1:2, 而竖屏需要比例为1:1。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="@layout/toolbar"/>
<!-- 因为在sm=800的情况下,那么左边只需要设置具体宽度为400,那么在横屏会有1:2的效果, 在竖屏下1:1的效果 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_below="@id/toolbar"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/layLeft"
android:layout_width="@dimen/_400dp"
android:layout_height="match_parent"/>
<FrameLayout
android:id="@+id/layRight"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"/>
</LinearLayout>
</RelativeLayout>
在适配的时候采用sw=800作为标准开发,命名规则为_XXdp, 比如在sw=800中需要使用10dp, 那么在values-sw800dp下增加一个<dimen name="_10dp">10dp</dimen>, 当完成开发后再写个脚本统一进行适配,比如在sw=600中,换算比例为600/800 = 3/4 , 那么在values-sw600dp下应该有个<dimen name="_10dp">7.5dp</dimen>, 同理在sw=360, sw=480, sw=720 或者更高的sw=1280 等.... 当然字体适配没有那么大的变化,一般来说只有那么几个常用的.