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系统之窗口横屏锁定以屏幕方向, 更多内容欢迎关注之后的文章
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步