Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //在onCreate中使用,rlRoot是根布局
- rlRoot.getViewTreeObserver().addOnGlobalLayoutListener(
- new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- if (!hasSetSize) {
- changeScreen();
- hasSetSize = true;
- }
- }
- });
- private void changeScreen() {
- DisplayMetrics displayMetrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
- int height = displayMetrics.heightPixels;
- int width = displayMetrics.widthPixels;
- if (getWindow().getDecorView().getWidth() == width) {
- getWindow().setLayout(
- (int) (width * Constants.SCREEN_MAIN_WIDTH
- / Constants.SCREEN_WIDTH),
- (int) (height * Constants.SCREEN_MAIN_HEIGHT
- / Constants.SCREEN_HEIGHT));
- } else {
- // getWindow().setLayout(width, height);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement