消息关闭
    暂无新消息!
新人学习android的vitamio时,播放电视源时,好像是视频源的尺寸太小,无法布满videoview,显示在左边,求大神前辈指导如何改到拉伸到全屏或在view的中间显示
目前状态:

13个回答

︿ 2
自定义一下view
public class CustomVideoView extends VideoView {

@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //我们重新计算高度
        int width = getDefaultSize(0, widthMeasureSpec);
        int height = getDefaultSize(0, heightMeasureSpec);
        setMeasuredDimension(width, height);
    }
︿ 2
外层套相对布局,设置  android:layout_centerInParent="true"  属性,我前不久刚做个这个

 <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >

            <VideoView
                android:id="@+id/video_view"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true" />
        </RelativeLayout>
︿ 1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/videoView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

注意红色
</LinearLayout>
︿ 1
重写VideoVIew 的onMeasure,
public class MyVideoView extends VideoView {
    public MyVideoView(Context context) {
        super(context);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        if (widthMode == MeasureSpec.EXACTLY && heightMode == MeasureSpec.EXACTLY) {
            setMeasuredDimension(widthSize, heightSize);
        } else {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
}
︿ 0
我在使用vitamio的时候希望他填充到一个区域中,不是全屏的,好像怎么设置都不行,有办法设置吗
︿ 0
有两种方法,仅供参考,共同学习,欢迎指正
1、通过LayoutParams即可设置视频源全屏
 @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
       
        if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        {
            Log.d("haha","切换横屏");
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        videoView.setLayoutParams(layoutParams);
        }
        super.onConfigurationChanged(newConfig);
    }

2、重写onMeasure,布局设置 match_parent

@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {

        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        if(widthMode == MeasureSpec.EXACTLY && heightMode == MeasureSpec.EXACTLY)
        {
            setMeasuredDimension(widthSize,heightSize);
        }
        else
        {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }