2011-12-12 62 views
0

我的XML代碼:Android的佈局priotity

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:id="@+id/relativeLayout2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:visibility="invisible"> 


     <ImageButton 
      android:id="@+id/video_playback_pause" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 


     <SeekBar 
      android:id="@+id/seekbar_video" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" android:layout_below="@id/video_playback_pause" android:clickable=""/> 

    </RelativeLayout> 

    <VideoView 
     android:id="@+id/videoView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerInParent="true" /> 

</RelativeLayout> 

現在磨片的RelativeLayout和VideoView覆蓋。 顯示VideoView,並隱藏RelativeLayout。 如何使VideoView頂部的RelativeLayout?

另一個問題是爲什麼seekbar沒有點擊?

我發現佈局的優先級是通過建立順序來決定的嗎? 但是seekbar的問題仍然沒有解決。

回答

1

嘗試......

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/RelativeLayout1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<RelativeLayout 
    android:id="@+id/relativeLayout2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > 


    <ImageButton 
     android:id="@+id/video_playback_pause" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 


    <SeekBar 
     android:id="@+id/seekbar_video" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" android:layout_below="@+id/video_playback_pause" android:clickable="true"/> 

</RelativeLayout> 

<VideoView 
    android:id="@+id/videoView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" /> 

</LinearLayout> 

編輯:

可以使用公開程度屬性如下

android:visibility="invisible" // invisible- just invisible the controls not the space 
           //gone - removes the allocated space too 
           //visible- shows the control 

在運行時也可以更改

mylayout.setVisibilty(View.GONE)... 
1

問題的第一部分的答案。
的android:layout_width = 「FILL_PARENT」 機器人:layout_height = 「FILL_PARENT」 機器人:layout_centerInParent = 「真」> 內的RelativeLayout的可見性設置爲invisible.Remove它。

您已經爲seekbar提供了android:clickable =「」。可能是這就是爲什麼它不工作。 刪除並嘗試。

希望這會幫助你。

+0

我只想在videoview觸摸時顯示relativeLayout2。所以我最初看不見。 – brian

+0

秒,它仍然沒有工作。 – brian

1

當談到喲你可能會有這樣的答案:設置

android:clickable="true" 

並且在你的java代碼中,試着放一個Event Listener。對於事件監聽器,http://developer.android.com/guide/topics/ui/ui-events.html

說到佈局,可以嘗試使用線性佈局,然後在其中嵌套相對佈局。你可能需要改變你的xml。