VideoView大小屏幕切换的总结

 http://blog.csdn.net/yaya_soft/article/details/22212119


最近做一个app要用到视频的播放,毫无疑问的选择了VieoView,但是在使用的时候发现VideoView全屏的时候还是有些学问的。。。先不管那么多了,把可以实现全屏与指定大小页面的效果的解决方案记录下来好了。。。

    步骤1:

      自定义一个VideoView,重写里面的onMeasure

      

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.jone.jonevideo.widget;  
  2.   
  3. import android.content.Context;  
  4. import android.util.AttributeSet;  
  5. import android.widget.VideoView;  
  6.   
  7. public class MyVideoView extends VideoView {  
  8.   
  9.     public MyVideoView(Context context, AttributeSet attrs, int defStyle) {  
  10.         super(context, attrs, defStyle);  
  11.     }  
  12.   
  13.     public MyVideoView(Context context, AttributeSet attrs) {  
  14.         super(context, attrs);  
  15.     }  
  16.   
  17.     public MyVideoView(Context context) {  
  18.         super(context);  
  19.     }  
  20.   
  21.     @Override  
  22.     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
  23.         // TODO Auto-generated method stub  
  24.   
  25.         int width = getDefaultSize(0, widthMeasureSpec);  
  26.         int height = getDefaultSize(0, heightMeasureSpec);  
  27.         setMeasuredDimension(width, height);  
  28.     }  
  29.   
  30. }  
步骤2: 用一个布局来包裹你的VideoView   [以后我们会在代码中控制VideoView的父布局来实现切换大小]

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <RelativeLayout  
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="match_parent" >  
  10.   
  11.         <com.jone.jonevideo.widget.MyVideoView  
  12.             android:id="@+id/audtoView"  
  13.             android:layout_width="match_parent"  
  14.             android:layout_height="match_parent" />  
  15.     </RelativeLayout>  
  16.   
  17.     <LinearLayout  
  18.         android:layout_width="match_parent"  
  19.         android:layout_height="wrap_content"  
  20.         android:layout_gravity="bottom" >  
  21.   
  22.         <Button  
  23.             android:id="@+id/audio_start"  
  24.             style="@style/layout_wrap_content"  
  25.             android:text="start_audio" />  
  26.   
  27.         <Button  
  28.             android:id="@+id/audio_2_video"  
  29.             style="@style/layout_wrap_content"  
  30.             android:text="@string/switch_audio_2_vidwo" />  
  31.   
  32.         <Button  
  33.             android:id="@+id/entry_list_audio"  
  34.             style="@style/layout_wrap_content"  
  35.             android:text="@string/entry_audio_list" />  
  36.     </LinearLayout>  
  37.   
  38. </FrameLayout>  

步骤3: 通过代码来设置全屏与否的切换

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. if(!fullscreen){//设置RelativeLayout的全屏模式  
  2.        RelativeLayout.LayoutParams layoutParams=  
  3.               new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);  
  4.            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);  
  5.            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);  
  6.            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);  
  7.            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);  
  8.            mVideoView01.setLayoutParams(layoutParams);  
  9.              
  10.            fullscreen = true;//改变全屏/窗口的标记  
  11.        }else{//设置RelativeLayout的窗口模式  
  12.           RelativeLayout.LayoutParams lp=new  RelativeLayout.LayoutParams(320,240);  
  13.           lp.addRule(RelativeLayout.CENTER_IN_PARENT);  
  14.             mVideoView01.setLayoutParams(lp);  
  15.             fullscreen = false;//改变全屏/窗口的标记  
  16.        }      

完事搞定

  http://liuzongming1988.iteye.com/blog/1926407这哥们写的挺详细。。我就参考了他的思路。。大家可以看看


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值