VideoView大小屏幕切换的总结
2014-03-26 21:18
399 查看
最近做一个app要用到视频的播放,毫无疑问的选择了VieoView,但是在使用的时候发现VideoView全屏的时候还是有些学问的。。。先不管那么多了,把可以实现全屏与指定大小页面的效果的解决方案记录下来好了。。。
步骤1:
自定义一个VideoView,重写里面的onMeasure
步骤3: 通过代码来设置全屏与否的切换
完事搞定
/article/4153003.html这哥们写的挺详细。。我就参考了他的思路。。大家可以看看
步骤1:
自定义一个VideoView,重写里面的onMeasure
package com.jone.jonevideo.widget; import android.content.Context; import android.util.AttributeSet; import android.widget.VideoView; public class MyVideoView extends VideoView { public MyVideoView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyVideoView(Context context, AttributeSet attrs) { super(context, attrs); } public MyVideoView(Context context) { super(context); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub int width = getDefaultSize(0, widthMeasureSpec); int height = getDefaultSize(0, heightMeasureSpec); setMeasuredDimension(width, height); } }步骤2: 用一个布局来包裹你的VideoView [以后我们会在代码中控制VideoView的父布局来实现切换大小]
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <com.jone.jonevideo.widget.MyVideoView android:id="@+id/audtoView" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" > <Button android:id="@+id/audio_start" style="@style/layout_wrap_content" android:text="start_audio" /> <Button android:id="@+id/audio_2_video" style="@style/layout_wrap_content" android:text="@string/switch_audio_2_vidwo" /> <Button android:id="@+id/entry_list_audio" style="@style/layout_wrap_content" android:text="@string/entry_audio_list" /> </LinearLayout> </FrameLayout>
步骤3: 通过代码来设置全屏与否的切换
if(!fullscreen){//设置RelativeLayout的全屏模式 RelativeLayout.LayoutParams layoutParams= new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mVideoView01.setLayoutParams(layoutParams); fullscreen = true;//改变全屏/窗口的标记 }else{//设置RelativeLayout的窗口模式 RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(320,240); lp.addRule(RelativeLayout.CENTER_IN_PARENT); mVideoView01.setLayoutParams(lp); fullscreen = false;//改变全屏/窗口的标记 }
完事搞定
/article/4153003.html这哥们写的挺详细。。我就参考了他的思路。。大家可以看看
相关文章推荐
- VideoView大小屏幕切换的总结
- VideoView大小屏幕切换的总结
- [Android学习笔记八] 使用VideoView屏幕方向发生变化,视频方向自动切换
- Android学习篇章48-VideoView视频播放-控制屏幕大小
- Android Tablayout + viewpager 切换时修改tablayout title(标题)的字体颜色和字体大小
- 自定义适应屏幕大小的TextView
- android 两个放置VideoView的Actitity来回切换BUG
- 总结View切换的三种方式
- android中viewPager+fragment实现的屏幕左右切换(进阶篇)
- 计算webView的 高度 和自适应屏幕大小
- ViewPager example -实现左右两个屏幕的切换
- Android利用ViewFlipper实现屏幕切换动画效果(下)
- android KTV 开发(一)自定义videoView 实现视频大小自由缩放、全屏与预览
- WebView设置自适应屏幕大小
- 使webview中的内容自适应屏幕大小
- WebView加载图片超过屏幕大小的问题
- ViewPager example -实现左右两个屏幕的切换
- Android利用ViewFlipper实现屏幕切换动画效果
- Android中使用ViewPager实现屏幕页面切换和引导页效果实现
- android webview 播放 video经验总结