一个videoview被另一个videoview屏蔽

问题描述:

我的活动布局如下所示。基本上我有一个左侧的列表视图菜单和两个视频切换,这取决于用户点击哪个菜单项。一个videoview被另一个videoview屏蔽

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_system_status" 
    android:title="@string/system_status" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:layout_weight="4"> 
     <ListView 
     android:id="@+id/list_video_feed" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     </ListView> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linear_layout_live_video" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:layout_weight="1"> 

     <VideoView 
     android:id="@+id/video_view" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" 
     /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linear_layout_video_gallery" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:layout_weight="1"> 

     <Gallery 
     android:id="@+id/gallery" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     /> 

     <VideoView 
     android:id="@+id/archived_video_view" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     /> 

    </LinearLayout> 

</LinearLayout> 

在我的代码,如果我想打从视图视频,而无需画廊,我隐藏其他。

linearLayoutVideoGallery.setVisibility(GONE); 
linearLayoutLiveVideo.setVisibility(VISIBLE); 
playVideo(); 

问题是,archived_video_view停留在顶部,只有画廊隐藏。有小费吗?如果您需要任何其他信息,请告知我。谢谢!

编辑:这是我的if语句,用于选择onCreate()内的菜单项。希望这会有所帮助。当我点击位置== 1,然后位置== 2时,画廊消失了,但是archived_video_view仍然处于暂停状态,所以我只能看到video_view的最上面一个画廊,就是画廊过去的位置。

  lv.setOnItemClickListener(new OnItemClickListener() { 
      public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 
       if (position==1) { //video gallery list item has been pressed 
        vvLive.stopPlayback(); 
        linearLayoutLiveVideo.setVisibility(GONE); 
        linearLayoutVideoGallery.setVisibility(VISIBLE); 
        playArchivedVideo(); 

       } 

       else if (position == 2) { //live video list item has been pressed 
        vvArchive.stopPlayback(); 
        linearLayoutVideoGallery.setVisibility(GONE); 
        linearLayoutLiveVideo.setVisibility(VISIBLE); 
        playLiveVideo(); 
       } 
      } 
      }); 
+0

您是否完全确定您正在使用正确的ID来获取linearLayoutVideoGallery和linearLayoutLiveVideo视图? – slund 2011-04-15 21:26:08

+0

是的。当我点击视频库,然后点击直播视频时,顶部的水平画廊就会隐藏起来,我只能看到现场视频播放的那条小条,因为存档视频仍处于前台。我用switch语句添加了一些额外的代码。谢谢。 – yellavon 2011-04-18 14:47:32

VideoViews是SurfaceViews。他们通过有效地将窗口弹出到硬件帧缓冲区来工作。但是,您只有一个这样的硬件帧缓冲区,您试图在两个SurfaceView中显示,以及使用两个MediaPlayers写入。因此,尝试玩弄多个SurfaceView时可能会出现大量渲染错误,并且这些错误在不同设备之间不一致。

最简单的答案是不要这样做。将每个VideoView分隔成单独的活动,或重建您的布局,以便共享单个视频视图。

下一个最简单的答案是不要同时做。在两个视频视图之间切换时,请在激活另一个视图视图之前删除一个(从View层次结构中完全删除它)也许在两者之间使用ImageView占位符,以保持用户界面相对一致,因为用户可以进行这种切换。