解决VideoView播放视频无法撑满全屏

一、造成原因:

由于VideoView 中的onMeasure走了自适应,导致两边无法撑满。

二、解决办法

因此,需要自定义布局,来进行重写onMeasure方法,让其两边为0即可。

     public static class fullVideoView extends VideoView {

        public fullVideoView(Context context) {
            super(context);
        }

        public fullVideoView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public fullVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }

        public fullVideoView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            //这里可以看到是将其设为0,不走其他的逻辑。可以去看源码原生逻辑,是还有判断的。
            int width = getDefaultSize(0, widthMeasureSpec);
            int height = getDefaultSize(0, heightMeasureSpec);
            setMeasuredDimension(width, height);
        }
    }

然后在布局中使用即可:

    <view class="com.android.abilitytest.ActivityVideo$fullVideoView"
        android:id="@+id/vv1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
三、结论

在很多不同的环境中,需要不同的自定义,因此自定义布局,很好的能解决这种问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值