2

我遇到了视频大小调整问题,我必须以编程方式构建布局,这是我的代码:

    layout = new RelativeLayout(this);
    top = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
    top.addRule(RelativeLayout.ALIGN_PARENT_TOP);

    RelativeLayout.LayoutParams middle = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    middle.addRule(RelativeLayout.BELOW, myText.getId());

    bottom = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
    bottom.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    layout.addView(myText,top);  
    layout.addView(myVideo,middle);
    layout.addView(myButtons,bottom);

    setContentView(layout);

根布局是相对布局。myText 是我想在根布局顶部添加的 Textview。接下来,我想在 myText 下方添加一个 VideoView。在根布局的底部,我想添加一些按钮。

myVideo 是一个 LinearLayout,定义如下:

    video = new VideoView(this);

    myVideo = new LinearLayout(this);
    myVideo.setGravity(0x11);
    videoParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    myVideo.setOrientation(LinearLayout.VERTICAL);
    myVideo.addView(video,videoParams);

在纵向模式下,视频显示在中间,视频占据整个宽度和适当的高度。在横向模式下,视频占据了整个屏幕(这是我想要的),而 myText 根本不显示。

谢谢克里斯

4

0 回答 0