直播app开发搭建,android系统之窗口横屏锁定以屏幕方向介绍

直播app开发搭建,android系统之窗口横屏锁定以屏幕方向介绍

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>        ...代码省略<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>        }<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;

 

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

 

posted @   云豹科技-苏凌霄  阅读(40)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
历史上的今天:
2022-06-08 php短视频源码,按钮的圆角图标实现
2022-06-08 直播app源码,定时开关,实现计时器功能
2022-06-08 直播平台源码,针对消息对话框的实际应用效果
点击右上角即可分享
微信分享提示