Android為TV端助力 修改videoview的寬度和高度


如果直接用android的videoview。他是不允許你隨意的修改寬度和高度的,所以我們要重寫videoview!

package com.hysmarthotel.view;

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));

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM