安卓屏幕适配

1.导入这个包
//屏幕适配
implementation 'me.yatoooon:screenadaptation:1.1.1'

在清单文件配置








2.在myapplication中初始化

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        ScreenAdapterTools.init(this);
    }


    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        ScreenAdapterTools.getInstance().reset(this);
    }
}

3.在activity中调用

public class MainActivity extends AppCompatActivity {
    private ServiceConnection serviceConnection;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ScreenAdapterTools.getInstance().loadView(getWindow().getDecorView());
    }

}

 

 

你可能感兴趣的:(android,android)