美文网首页AndroidAndroid知识Android开发
Android 使用VideoView播放视频无法全屏问题

Android 使用VideoView播放视频无法全屏问题

作者: 筱南独舞 | 来源:发表于2017-04-12 19:01 被阅读2689次

在VideoView宽高都设置为match_parent后,由于视频源的尺寸导致播放的时候不能全屏,只需要重写VideoView的onMeasure方法就可以了,代码如下,直接copy就可以用了。

import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;

/**
 * Created by lijingnan on 12/04/2017.
 */
public class CustomerVideoView extends VideoView {

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

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

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

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // 其实就是在这里做了一些处理。
        int width = getDefaultSize(0, widthMeasureSpec);
        int height = getDefaultSize(0, heightMeasureSpec);
        setMeasuredDimension(width, height);
    }
}

相关文章

网友评论

  • 一个没有梦想的人_ac0b:问下: 为什么有写很小的视频源还是无法全屏, 比如320*280之类的, 总是高度方向不全屏~谢谢
  • 有情绪的仙人掌:为何不解释一下参数:fearful:
    筱南独舞:@有情绪的仙人掌 啊?这就是自定义View时最最基础的东西啦,所以就没有解释了,其实分析一下也能看出是什么意思的:stuck_out_tongue_winking_eye:

本文标题:Android 使用VideoView播放视频无法全屏问题

本文链接:https://www.haomeiwen.com/subject/fhzmattx.html