1

I have a MtxVideoView class which contains textview and surfaceview. The MtxVideoView class extends FrameLayout. I want to change size of MtxVideoView . How can do that ?

Following the code of special view

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);
}
}
Riskhan
  • 4,434
  • 12
  • 50
  • 76

2 Answers2

0

Try this code. But you have to run it when view is already measured.

{
    LayoutParams param = getLayoutParams();
    param.width = 100;
    param.height = 200;
    requestLayout();
}
zinuzoid
  • 337
  • 8
  • 14
0

When defining in xml use layout_width and layout_hight.

If you are adding dynamically then set layout parameters or add this view with layout parameters to its parent.

Simpalm
  • 1
  • 5