2010-11-26 53 views
0

我有一個應用程序使用以下視圖對象的佈局。 2個旋鈕,2個按鈕,1個seekbar和一個自定義視圖對象,該對象基本上是我繪製的畫布。什麼控制視圖在界面上出現的順序?

出於某種原因,spinners和seekbar被繪製在畫布的頂部,但2個按鈕不是。我很困惑,爲什麼這是。

那麼,這個命令是如何確定的?

感謝。

編輯:請求XML(這是在我將customview移動到解決問題的頂端之前)。如果訂單應該是基於XML的,那麼定製視圖應該覆蓋它沒有的紡紗工。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <Spinner 
     android:id="@+id/cc_component" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:drawSelectorOnTop="true" 
     android:prompt="@string/cc_component_spinner" /> 

    <TextView 
     android:id="@+id/desc" 
     android:text="@string/step1_desc" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dip" 
     android:visibility="gone" 
     android:layout_centerHorizontal="true" 
     android:textSize="25sp"/> 

    <Button 
     android:id="@+id/switch_left" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true"/> 

    <com.cmllc.zcc.CCView 
     android:id="@+id/cc" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <Button 
     android:id="@+id/switch_right" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:background="@drawable/rightarrow1" /> 

    <Spinner 
     android:id="@+id/component_color" 
     android:layout_above="@+id/switch_color" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:drawSelectorOnTop="true" 
     android:prompt="@string/component_color_spinner" /> 

    <SeekBar 
     android:id="@+id/switch_color" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:max="100" 
     android:minWidth="200dip" 
     android:progress="50"/> 

</RelativeLayout> 
+0

,如果你能在這裏展示您的佈局文件的代碼......我也許能幫助 – 2010-11-26 02:52:04

回答

1

它應該只是它們添加到視圖的順序。除此之外,您可以使用View.bringChildToFront()

看到這個職位:Defining Z order of views of RelativeLayout in Android

而且在post here由戴安娜Hackborn,在谷歌的Android開發者,她表示關於z順序行爲同樣的事情。

我實現您的佈局,或儘可能接近,因爲我可以不用你所有的資源和自定義View的對象,而我得到的結果,我除了。第一次微調,TextView的,並且按鈕顯示自定義對象,我用下面的模仿下:

<TextView 
    android:id="@+id/cc" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#880000FF" /> 

我再看看第二個按鈕,第二微調,和搜索條之上。你在自定義視圖中做了什麼奇怪的事情?這或者可能是由於後來操縱你的觀點而發生的事情。

編輯:我仔細檢查了,我確實確實看到顯示爲我描述上述

+0

好吧,我提出我的自定義視圖的XML文件中,雖然它沒有解決我的問題,我仍然感到困惑。如果XML文件是主文件,那麼應該已經用我的自定義視圖(Canvas)覆蓋了旋轉函數,因爲它們是在自定義視圖之前用XML定義的。 – user432209 2010-11-26 02:57:31

+0

我不確定這種情況。如果你發佈了相關的源代碼,我們可能能夠更好地確定爲什麼你正在得到你的結果。 – Thomas 2010-11-26 03:00:10

0

你不是相對於其他任何設置你的任何意見。在相對佈局中,您需要告訴視圖您的視圖位於其他視圖的上方,下方等。你需要給他們一些相關的設置,而不僅僅是對其中的一些進行align_parent。

相關問題