@mSolo
2015-04-17T00:07:55.000000Z
字数 2069
阅读 1561
Android
适配
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.
密度 | 取值 |
---|---|
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 | 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 |
public int convertToPixelFromDp(int dpInput) {
// The density for the current device
// getResources().getConfiguration().densityDpi;
// get the screen's density scale
final float scale = getResources().getDisplayMetrics().density;
// convert the dps to pixels, based on density scale
return (int) (dpInput * scale + 0.5f)
}
<resources>
<item name="main" type="layout">@layout/main_tablet</item>
</resources>
Android 的资源文件夹结构非常强大, 它允许开发者将不同的图片、字符串、布局文件、外形、颜色这些资源,在api、代码、屏幕尺寸等部分.
在 values-small 文件夹中存放了一个 bools.xml 文件, 文件中有如下几行代码 :
<resources>
<boolname="small_screen">true</bool>
</resources>
if ( getResources().getBoolean(R.bool.small_screen) ) {
getSupportActionBar().hide();
}
<resources>
<boolname="small_screen">false</bool>
</resources>