关于SurfaceView横竖屏切换显示问题
来源:互联网 发布:linux home空间 编辑:程序博客网 时间:2024/05/19 13:25
我们一般都会用SurfaceView做预览和播放,话不多说,直接上代码清单文件中设置好代码中实现onConfigurationChanged()方法
android:configChanges="orientation|screenSize
@Overridepublic void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
//竖屏显示 LayoutParams lp = mSurface.getLayoutParams(); lp.width = lp.MATCH_PARENT; lp.height = 680; mSurface.setLayoutParams(lp); } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
//横屏显示 LayoutParams lp = mSurface.getLayoutParams(); lp.width = lp.MATCH_PARENT; lp.height =lp.MATCH_PARENT; mSurface.setLayoutParams(lp); }
通过判断横竖屏来设置surfaceView的宽高就可以了,有的需求是横竖屏切换后要保持一定的比例,请看下面
DisplayMetrics dm = new DisplayMetrics();if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm); int screenWidth = dm.widthPixels; int screenHeigh = dm.heightPixels; LayoutParams lp = mSurface.getLayoutParams(); lp.width = screenWidth; lp.height = screenWidth * 9/16; mSurface.setLayoutParams(lp);} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm); int screenWidth = dm.widthPixels; int screenHeigh = dm.heightPixels; LayoutParams lp = mSurface.getLayoutParams(); lp.width = screenHeigh*16/9; lp.height =screenHeigh; mSurface.setLayoutParams(lp);}
获取手机系统的宽高,你想要什么比例就按比例计算就可以了。
1 0
- 关于SurfaceView横竖屏切换显示问题
- 关于Android 横竖屏切换的问题
- 关于android 横竖屏切换问题阐述
- 横竖屏切换SurfaceView 大小的调整
- 关于 横竖屏切换
- 切换横竖屏问题
- 横竖屏切换问题
- 横竖屏切换问题
- 横竖屏切换及显示
- 横竖屏切换后CEikSecretEditor输入不显示问题
- 关于Activity横竖屏切换
- android关于横竖屏切换
- 关于横竖屏切换问题几点知识:
- 关于安卓横竖屏切换问题(学习总结)
- 关于横竖屏切换时Activity生命周期的问题
- 关于屏幕横竖屏切换,生命周期的问题
- 关于dialog横竖屏切换不能全屏问题
- android surfaceview自定义视频播放器横竖屏切换总结
- MemCache超详细解读
- leetcode:69. Sqrt(x)
- 在 C# 中使用 C++
- MySQL索引的使用
- 第6天HBase笔记
- 关于SurfaceView横竖屏切换显示问题
- iOS 基于环信SDK实现即时通讯-文字聊天
- Apache Thrift 配置和使用指南
- selenium 如何获取分页数据
- Retrofit2学习笔记-1
- 素数筛法详解
- javascript中的异步编程的4种方法
- 数据结构---链表和数组
- 从Visual Studio看微软20年技术变迁