直播app开发搭建,android系统之窗口横屏锁定以屏幕方向介绍
直播app开发搭建,android系统之窗口横屏锁定以屏幕方向介绍
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;
以上就是直播app开发搭建,android系统之窗口横屏锁定以屏幕方向介绍, 更多内容欢迎关注之后的文章