一分鐘了解Android橫豎屏 mdpi hdpi xhdpi xxhdpi xxxhdpi
DPI:每英寸像素數
簡單的屏幕分辨率計算方法:
DisplayMetrics metrics = this.getResources().getDisplayMetrics();
float density = metrics.density;
int dpi = metrics.densityDpi;
int heightPixels = metrics.heightPixels;
int widthPixels = metrics.widthPixels;
Log.e("---metrics---", "比例:"+density+"dpi:"+dpi+"高像素:"+heightPixels+"寬像素:"+widthPixels);
dp與px計算圖(mdpi 1dp=1px):
ldpi:1dp=0.75px mdpi:1dp=1px hdpi:1dp=1.5px xhdpi:1dp=2px xxhdpi:1dp=3px xxxhdpi:1dp=4px
Android手機屏幕標準 相應圖標尺寸標準 屏幕密度 比例
xxxhdpi 3840*2160 192*192 640 16
xxhdpi 1920*1080
xhdpi 1280*720 96*96 320 8
hdpi 480*800 72*72 240 6
mdpi 480*320 48*48 160 4
ldpi 320*240 36*36 120 3
註:Android studio mipmap目錄僅僅存放啟動圖標icon
http://blog.csdn.net/a704755096/article/details/46342689
屏幕橫豎屏布局切換:
1)單個布局xml直接橫豎屏切換。不又一次載入數據:android:configChanges="orientation|keyboardHidden|screenSize"
2)layout-land和layout-port布局橫豎屏切換。不又一次載入數據:FragmentActivity重寫onRetainCustomNonConfigurationInstance()
Activity 重寫onRetainNonConfigurationInstance()保存數據。在onCreate()時推斷getLastNonConfigurationInstance()是否null:
Java代碼- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Object data = getLastNonConfigurationInstance();
- if (data == null) {
- findviewbyidLoadMyData();
- }
- ...
- }
很多其它:安卓圖片動畫(http://www.open-open.com/lib/view/open1335777066015.html)、點九圖工具:
1.打開Android project包 SDK文件。tools文件,雙擊draw9patch.bat
2.彈出的窗體點擊 File,點擊要編輯的圖片open 9patch
3.編輯。鼠標左鍵:劃線 / shift + 鼠標左鍵:刪除劃線
4.保存。點擊save 9patch
一分鐘了解Android橫豎屏 mdpi hdpi xhdpi xxhdpi xxxhdpi