VideoView控件可以手动改变大小
16lz
2021-01-23
Android中的videoview控件在android中不能设置宽高,需要重写videoView中的onMeasure()方法,才可以设置videoview的宽和高。重写的videoview代码如下:
让VideoView可以手动的设置长宽
/** * The CustomVideoView is to make videoView view length-width based on the parameters you set to decide. * @author peter. * */public class CustomVideoView extends VideoView {private int mVideoWidth; private int mVideoHeight; public CustomVideoView(Context context) { super(context); } public CustomVideoView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomVideoView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { /* The following code is to make videoView view length-width based on the parameters you set to decide. */ int width = getDefaultSize(mVideoWidth, widthMeasureSpec); int height = getDefaultSize(mVideoHeight, heightMeasureSpec); setMeasuredDimension(width, height); }}
更多相关文章
- Android 自动化测试—robotium(五)Spinner控件
- Android TextView内容居中和控件居中
- 系出名门Android(5) - 控件(View)之TextView, Button, ImageButt
- Android学习笔记35——ProgressBar进度控件详解
- 【Android 开发】:UI控件之 ListView 列表控件的使用
- Android 中的时间日期控件
- IKNinePhotoView 是一个开源的 Android 九宫格控件,可以自适应宽
- Android之——自定义复合控件的实现