android短视频开发,android系统之窗口横屏锁定以屏幕方向
android短视频开发,android系统之窗口横屏锁定以屏幕方向
android源码中通过PhoneWindowManager.java来管理窗口的显示,为WMS的一个主要部分。其源码地址如下:
frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.java
PhoneWindowManager关于屏幕方向控制的主要代码如下:
int mLandscapeRotation = 0; // default landscape rotation
int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
int mPortraitRotation = 0; // default portrait rotation
int mUpsideDownRotation = 0; // "other" portrait rotation
@Override
public void setInitialDisplaySize(Display display, int width, int height, int density) {
final Resources res = mContext.getResources();
int shortSize, longSize;
if (width > height) {
shortSize = height;
longSize = width;
mLandscapeRotation = Surface.ROTATION_0;
mSeascapeRotation = Surface.ROTATION_180;
if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
mPortraitRotation = Surface.ROTATION_90;
mUpsideDownRotation = Surface.ROTATION_270;
} else {
mPortraitRotation = Surface.ROTATION_270;
mUpsideDownRotation = Surface.ROTATION_90;
}
} else {
shortSize = width;
longSize = height;
mPortraitRotation = Surface.ROTATION_0;
mUpsideDownRotation = Surface.ROTATION_180;
if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
mLandscapeRotation = Surface.ROTATION_270;
mSeascapeRotation = Surface.ROTATION_90;
} else {
mLandscapeRotation = Surface.ROTATION_90;
mSeascapeRotation = Surface.ROTATION_270;
}
}
landscape就是的横屏(seascape就是其对面),portrait就是竖屏(upsidedown就是竖屏对立面)。
横屏和竖屏决定了应用的横竖屏方向,如应用的AndroidMenifest.xml中android:screenOrientation=“portrait”,那么该apk运行的window view方向就是mPortraitRotation指定的方向。
通过获取宽高,判断宽高大小来决定显示逻辑,获取android设备的屏幕分辨率:
DisplayMetrics dm = getResources().getDisplayMetrics();
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
以上就是android短视频开发,android系统之窗口横屏锁定以屏幕方向, 更多内容欢迎关注之后的文章