android 修改videoview的宽度和高度
2017-06-22 10:02
495 查看
如果直接用android的videoview,它是不允许你随意的修改宽度和高度的,所以我们要重写videoview!
import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;
public class MyVideoView extends VideoView{
public MyVideoView(Context context) {
super(context);
}
public MyVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyVideoView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getDefaultSize(getWidth(), widthMeasureSpec);
int height = getDefaultSize(getHeight(), heightMeasureSpec);
setMeasuredDimension(width, height);
}
}
主要就是onMeasure方法,我们重写的onMeasure方法而不用谷歌的,这样我们就可以随意的控制videoview的宽度和高度
2.还有一种方法是修改
import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;
public class MyVideoView extends VideoView{
public MyVideoView(Context context) {
super(context);
}
public MyVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyVideoView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getDefaultSize(getWidth(), widthMeasureSpec);
int height = getDefaultSize(getHeight(), heightMeasureSpec);
setMeasuredDimension(width, height);
}
}
主要就是onMeasure方法,我们重写的onMeasure方法而不用谷歌的,这样我们就可以随意的控制videoview的宽度和高度
2.还有一种方法是修改
holder = surfaceView.getHolder();
holder.setFixedSize(mVideoWidth, mVideoHeight); 这样也可以改变视频控件的宽度和高度 3.第三种方法是直接修改
mMediaSurfaceView.setLayoutParams(new RelativeLayout.LayoutParams(600,600));
相关文章推荐
- Android实现图片宽度100%ImageView宽度且高度按比例自动伸缩
- android ImageView 宽度设定,高度自适应
- Android获取屏幕或View宽度和高度的方法
- Android 修改videoview的宽高
- Android 设置ImageView宽度固定,其高度按比例缩放适应
- android 用java代码设置布局、视图View的宽度/高度或自适应
- Android 自定义imageview图片高度固定大小宽度按比例自适应
- android 开发技巧(11)--在 onCreate() 方 法 中 获 取 View 的 宽度和高度
- Android 自定义imageview 图片高度固定大小宽度按比例自适应
- Android 在代码中控制View的填充方式和宽度、高度
- 2015001 读书笔记:android在onCreate中获得view高度和宽度
- Android - 小知识点 (View 添加 虚线 , ImageView适应图片宽度和高度)
- android 中 view 的宽度和高度
- 代码中修改ImageView的高度和宽度
- Android实现图片宽度100%ImageView宽度且高度按比例自动伸缩
- Android 获取View的高度和宽度
- Android 设置ImageView宽度固定,其高度按比例缩放适应
- Android 设置ImageView宽度固定,其高度按比例缩放适应
- Android实现图片宽度100%ImageView宽度且高度按比例自动伸缩
- Android基础UI之ImageView宽度设定,高度自适应