Android Studio检测屏幕旋转

检测屏幕转向,对UI进行相应调整。

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Checks the orientation of the screen
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
            Log.d(TAG, "onConfigurationChanged: landscape");
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
            Log.d(TAG, "onConfigurationChanged: portait");
        }
    }

你可能感兴趣的:(Android Studio检测屏幕旋转)