我有一个包含textview和surfaceview的MtxVideoView类。 MtxVideoView类扩展了FrameLayout。我想改变MtxVideoView的大小。怎么办?
遵循特殊视图代码
public class MtxVideoView extends FrameLayout implements SurfaceHolder.Callback, MediaPlayer.OnPreparedListener,
VideoControllerView.MediaPlayerControl, MediaPlayer.OnErrorListener {
private Context mContext;
private SurfaceHolder mSurfaceHolder;
private SurfaceView mSurfaceView;
private MediaPlayer mPlayer;
private VideoControllerView controller;
private TextView mMessage;
private boolean mbSrcAvailable = false;
private boolean mbSurfaceCreated = false;
private String mSource = "";
private String mUserName = "";
private String mPassword = "";
private boolean mbFullscreen = false;
private FullScreenListener mFullScreenListener;
private int mCount = 0;
static interface FullScreenListener {
void onFullScreen( View view, boolean bFullScreen);
}
public void setFullScreenListener( FullScreenListener listener ){
mFullScreenListener = listener;
}
public MtxVideoView(Context context) {
super(context);
mContext = context;
mbFullscreen = false;
Init();
}
public MtxVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
Init();
}
public MtxVideoView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
Init();
}
private void Init(){
mSurfaceView = new SurfaceView(mContext);
mSurfaceView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT ));
addView(mSurfaceView);
mMessage = new TextView(mContext);
mMessage.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT ));
mMessage.setGravity(Gravity.CENTER);
mMessage.setTextColor(Color.WHITE);
this.addView(mMessage);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
}
}
答案 0 :(得分:0)
试试这段代码。 但是,当已经测量了视图时,您必须运行它。
{
LayoutParams param = getLayoutParams();
param.width = 100;
param.height = 200;
requestLayout();
}
答案 1 :(得分:0)
在xml中定义时使用layout_width和layout_hight。
如果要动态添加,请设置布局参数或将此视图与布局参数一起添加到其父级。