屏幕适配
只需要修改两个地方:
implementation 'me.jessyan:autosize:1.1.2'
添加设置屏幕宽高,注意屏幕的横/竖适当修改如下大小,下面两行就是把宽设置成480dp,高设置成800dp,布局的时候屏幕尺寸单位就按照dp的方式设置:
<meta-data
android:name="design_width_in_dp"
android:value="480"/>
<meta-data
android:name="design_height_in_dp"
android:value="800"/>
布局时使用dp为单位即可:
屏幕尺寸获取
WindowManager manager = this.getWindowManager();
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
int width = outMetrics.widthPixels;
int height = outMetrics.heightPixels;
判断当前横竖屏状态
Configuration configuration = getResources().getConfiguration();
if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
System.out.println("竖屏");
}