最終更新:2018-03-12 (月) 16:40:20 (2237d)
Android/dp
dip: density-independent pixel
計算
- dp×DisplayMetrics.getDisplayMetrics().density = px
- dp = px / DisplayMetrics.getDisplayMetrics().density
- DPI=160のときにdp=px
- DPI=320だとdp=px/2
density
- (dpi / 160)
ro.sf.lcd_density
Nexus 9 320 Nexus 7 (初代) 213 Nexus 7 (2013) 320 Nexus Player 320 Nexus 4 320 Nexus 5 480 Nexus 5X 420 Nexus 6 560 Nexus 6P 560
Android/設定修飾子
- Android 3.2以降ではAndroid/構成修飾子?でdpを使う。
基準
- The generalized sizes and densities are arranged around a baseline configuration that is a normal size and mdpi (medium) density.
- This baseline is based upon the screen configuration for the first Android-powered device, the T-Mobile G1 (ADP1), which has an HVGA screen (until Android 1.6, this was the only screen configuration that Android supported).
優先順位
- xxx-h<N>dp > xxx-sw<N>dp > xxx-w<N>dp > xxx(デフォルト)
dpの例
- 320dp?: a typical phone screen (240x320 ldpi?, 320x480 mdpi, 480x800 hdpi?, etc).
- 480dp?: a tweener tablet like the Streak (480x800 mdpi).
- 600dp: a 7" tablet (600x1024 mdpi).
- 720dp?: a 10" tablet (720x1280 mdpi, 800x1280 mdpi, etc).
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)