LinearLayout下的VideoView,不可见

时间:2011-12-08 14:39:11

标签: android android-linearlayout viewflipper android-videoview

我向VideoView添加了LinearLayout,我无法在屏幕上看到它,LinearLayout就在它前面。之后LinearLayout添加到ViewFlipper这是我的代码:

    LinearLayout rr = new LinearLayout(this);
    rr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    myVideoView = new VideoView(this);
    myVideoView.setVideoPath(Environment.getExternalStorageDirectory()
                    +"/download/"+"big_buck_bunny.mp4");
    myVideoView.requestFocus();
    myVideoView.bringToFront();

    rr.addView(myVideoView,new LayoutParams(rr.getWidth(),rr.getHeight()));
    vf.addView(rr);

任何人都可以帮助我???拜托......我的错误在哪里?我看不到它。

1 个答案:

答案 0 :(得分:0)

rr.getWidth / Height()返回大小为0可能是因为它们尚未被测量。

getWidth / Height()返回视图的大小(以像素为单位),因为您已将rr的布局参数指定为fill_parent,使用getWidth / Height的fill_parent是不必要的。

尝试替换

rr.addView(myVideoView,new LayoutParams(rr.getWidth(),rr.getHeight()));

rr.addView(myVideoView,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));