美文网首页
Android Studio检测屏幕旋转

Android Studio检测屏幕旋转

作者: 汶水一方 | 来源:发表于2017-11-03 02:02 被阅读162次

检测屏幕转向,对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检测屏幕旋转

      本文链接:https://www.haomeiwen.com/subject/kuszpxtx.html