android短视频开发,android系统之窗口横屏锁定以屏幕方向

android短视频开发,android系统之窗口横屏锁定以屏幕方向

android源码中通过PhoneWindowManager.java来管理窗口的显示,为WMS的一个主要部分。其源码地址如下:

 

1
<br>frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.java

​PhoneWindowManager关于屏幕方向控制的主要代码如下:

 

1
<br>    int mLandscapeRotation = 0;  // default landscape rotation<br>    int mSeascapeRotation = 0;   // "other" landscape rotation, 180 degrees from mLandscapeRotation<br>    int mPortraitRotation = 0;   // default portrait rotation<br>    int mUpsideDownRotation = 0; // "other" portrait rotation<br>@Override<br>    public void setInitialDisplaySize(Display display, int width, int height, int density) {<br>        final Resources res = mContext.getResources();<br>        int shortSize, longSize;<br>        if (width > height) {<br>            shortSize = height;<br>            longSize = width;<br>            mLandscapeRotation = Surface.ROTATION_0;<br>            mSeascapeRotation = Surface.ROTATION_180;<br>            if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {<br>                mPortraitRotation = Surface.ROTATION_90;<br>                mUpsideDownRotation = Surface.ROTATION_270;<br>            } else {<br>                mPortraitRotation = Surface.ROTATION_270;<br>                mUpsideDownRotation = Surface.ROTATION_90;<br>            }<br>        } else {<br>            shortSize = width;<br>            longSize = height;<br>            mPortraitRotation = Surface.ROTATION_0;<br>            mUpsideDownRotation = Surface.ROTATION_180;<br>            if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {<br>                mLandscapeRotation = Surface.ROTATION_270;<br>                mSeascapeRotation = Surface.ROTATION_90;<br>            } else {<br>                mLandscapeRotation = Surface.ROTATION_90;<br>                mSeascapeRotation = Surface.ROTATION_270;<br>            }<br>        }

 

landscape就是的横屏(seascape就是其对面),portrait就是竖屏(upsidedown就是竖屏对立面)。

横屏和竖屏决定了应用的横竖屏方向,如应用的AndroidMenifest.xml中android:screenOrientation=“portrait”,那么该apk运行的window view方向就是mPortraitRotation指定的方向。

通过获取宽高,判断宽高大小来决定显示逻辑,获取android设备的屏幕分辨率:

 

1
<br>     DisplayMetrics dm = getResources().getDisplayMetrics();<br>     int screenWidth = dm.widthPixels;<br>     int screenHeight = dm.heightPixels;

 

以上就是android短视频开发,android系统之窗口横屏锁定以屏幕方向, 更多内容欢迎关注之后的文章

 

posted @   云豹科技-苏凌霄  阅读(94)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示