VideoView大小屏幕切换的总结

VideoView大小屏幕切换的总结

分类:android

VieoView 全屏切换

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

步骤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);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {// TODO Auto-generated method stubint width = getDefaultSize(0, widthMeasureSpec);int height = getDefaultSize(0, heightMeasureSpec);setMeasuredDimension(width, height);}}步骤2: 用一个布局来包裹你的VideoView [以后我们会在代码中控制VideoView的父布局来实现切换大小]

<FrameLayout xmlns:android=""xmlns:tools=""android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent" ><com.jone.jonevideo.widget.MyVideoViewandroid:id="@+id/audtoView"android:layout_width="match_parent"android:layout_height="match_parent" /></RelativeLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="bottom" ><Buttonandroid:id="@+id/audio_start"style="@style/layout_wrap_content"android:text="start_audio" /><Buttonandroid:id="@+id/audio_2_video"style="@style/layout_wrap_content"android:text="@string/switch_audio_2_vidwo" /><Buttonandroid: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;//改变全屏/窗口的标记} 完事搞定

这哥们写的挺详细。。我就参考了他的思路。。大家可以看看

版权声明:本文为博主原创文章,未经博主允许不得转载。

上一篇android中xml直接转json下一篇Vitamio打造android个性化得播放器

我不敢说我明天便可以做一个快乐的人,面朝大海春暖花开。

VideoView大小屏幕切换的总结

相关文章:

你感兴趣的文章:

标签云: