user432209
user432209

Reputation: 20177

What controls the order of view's appearing on the screen on the UI?

I have an app with a layout using the following view objects. 2 spinners, 2 buttons, 1 seekbar and a custom view object that is basically a canvas I draw to.

For some reason the spinners and seekbar are drawn on top of the canvas, but the 2 buttons are not. I'm confused as to why this is.

So, how is this ordered determined?

Thanks.

Edit: XML at request (this is before I moved the customview to the top which fixes the problem). If the order is supposed to be XML based then the custom view should have covered the spinners which it did not.

<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>

Upvotes: 0

Views: 732

Answers (2)

Thomas
Thomas

Reputation: 3693

It should just be the order in which they are added to the view. Other than that you can use View.bringChildToFront().

See this post: Defining Z order of views of RelativeLayout in Android

And in a post here by Dianne Hackborn, an Android Developer at Google, she indicates the same thing regarding z-order behavior.

I implemented your layout, or as closely as I could without all of your resources and custom View object, and I get the results I except. The first spinner, textview, and button appear underneath the custom object, which I am imitating with the following:

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

I then see the second button, second spinner, and seekbar on top. Are you doing anything weird with your custom view? That or perhaps it is something happening due to later manipulation of your views.

Edit: I double checked and I do indeed see the display as I describe above

Upvotes: 1

Falmarri
Falmarri

Reputation: 48577

You're not setting any of your views relative to any others. In a relative layout, you need to tell the view that your views are above, below, etc other views. You need to give them relative settings, not just align_parent on a few of them.

Upvotes: 0

Related Questions