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*1080144*144
480 12
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
屏幕横竖屏布局切换:
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();
}
...
}
1.打开Android project包 SDK文件。tools文件,双击draw9patch.bat
2.弹出的窗体点击 File,点击要编辑的图片open 9patch
3.编辑。鼠标左键:划线 /shift + 鼠标左键:删除划线
4.保存。点击save 9patch