[关闭]
@mSolo 2015-04-17T00:07:55.000000Z 字数 2069 阅读 1561

Android 开发适配索引贴

Android 适配


自 Android 3.2( API 13)起

For a 640dp×480dp screen
resource-sw__dp : always has a smallest width of 480dp.
resource-w___dp : 640dp when in landscape and 480dp when in portrait.
resource-h___dp : 640dp when in portrait and 480dp when in landscape.

密度(Density)

密度 取值
ldpi 160 dpi x 0.75
mdpi 160 dpi
hdpi 1.5 x 160 dpi = 240 dpi
xhdpi 2 x 160 dpi = 320 dpi
xxhdpi 3 x 160 dpi = 480 dpi
xxxhdpi 4 x 160 dpi = 640 dpi

Icon 的大小

Icon mdpi hdpi xhdpi xxhdpi xxxhdpi
Launcher 48px 72px 96px 144px 192px
Action bar 32px 48px 64px 96px 128px
Notification bar 24px 36px 48px 72px 96px

dp 转换为 px 方法

  1. public int convertToPixelFromDp(int dpInput) {
  2. // The density for the current device
  3. // getResources().getConfiguration().densityDpi;
  4. // get the screen's density scale
  5. final float scale = getResources().getDisplayMetrics().density;
  6. // convert the dps to pixels, based on density scale
  7. return (int) (dpInput * scale + 0.5f)
  8. }

Layout Aliases

  1. <resources>
  2. <item name="main" type="layout">@layout/main_tablet</item>
  3. </resources>

使用文件夹

  1. <resources>
  2. <boolname="small_screen">true</bool>
  3. </resources>
  1. if ( getResources().getBoolean(R.bool.small_screen) ) {
  2. getSupportActionBar().hide();
  3. }
  1. <resources>
  2. <boolname="small_screen">false</bool>
  3. </resources>

设计事项

设计索引

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注