2013-02-19 99 views
0

林很新的Android開發..Android設備上查看顯示舉例Z訂購

它看起來像ImageView的ontop的是在VideoView的,因此VideoView不顯示。這是真的?當我想要顯示視頻時,是否需要更改視圖的順序?並再次當imageView必須顯示圖像?

我循環顯示圖像和視頻列表並顯示圖像x秒,然後轉到下一個元素,可能是視頻或圖像。

這是我的佈局:

<LinearLayout 
    android:id="@+id/LinearLayout01" 
    android:layout_height="fill_parent"  
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:orientation="horizontal"> 
    <ImageView 
     android:contentDescription="@raw/image" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:scaleType="fitCenter" 
     android:id="@+id/imageView" /> 
    <VideoView 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:scaleType="fitCenter" 
     android:id="@+id/videoView" /> 

<!--  <SurfaceView 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
      android:id="@+id/surface" /> --> 


</LinearLayout> 

回答

2

這不是Z排序那是你的問題。你有一個LinearLayout有兩個視圖。它設置爲horizontal,所以它想要將它們彼此相鄰。但是,您使用的寬度爲fill_parent,因此第一個視圖佔用了所有空間,而下一個視圖從屏幕上向外(右側)繪製。

一個簡單的解決方案是當您想要顯示一個或另一個時,翻轉視圖的visibility狀態。我敢肯定,有更多優雅的方式可以做到這一點,但這很簡單。

+0

你的意思是這樣的:View.setVisibility(View.GONE/View.VISIBLE/View.INVISIBLE)。 ? – Harry 2013-02-19 15:37:11

+0

是的,就像那樣。你只需要跟蹤哪一個是可見的,哪一個是沒有的。我不會推薦'INVISIBLE',因爲它在'INVISIBLE'時仍然佔據它的佈局空間。 – Geobits 2013-02-19 15:40:19

+0

很酷,讓我試試這個:-) – Harry 2013-02-19 15:45:03

0

由於imageView和videoView在同一個LinearLayout中,它們彼此相鄰顯示;不在另一層。

我猜VideoView沒有顯示,因爲你沒有鏈接任何內容。至少那是我的日食顯示。