0

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>
user432209
  • 20,007
  • 10
  • 56
  • 75

2 Answers2

1

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

Community
  • 1
  • 1
Thomas
  • 3,603
  • 1
  • 18
  • 23
  • Alright, I moved my custom view inside the XML file and while it did solve my problem, I'm still confused. If the XML file is the master, then the spinners should have been covered by my custom view (Canvas) since they were defined in XML before the custom view. – user432209 Nov 26 '10 at 02:57
  • I'm unsure about that specific situation. If you post the relevant source code we may be able to better determine why precisely you were getting the result you were. – Thomas Nov 26 '10 at 03:00
  • Are you messing with any of their layout related settings in code, or is that pretty much all you're doing with them right now? Also, is that the version that gives you the undesired result? – Thomas Nov 26 '10 at 03:25
  • @user432209 Works as expected for me, see above. – Thomas Nov 26 '10 at 03:44
  • I am not messing with much in code...just a View.GONE or View.VISIBLE here or there. Since your getting different results without the custom view that tells me the problem is either my code in the custom view or just the way Android interprets it. Thanks for the help! – user432209 Nov 26 '10 at 12:31
  • I'm going to double check it once more when I get home. Regardless, it isn't a huge deal as you can get your desired result by moving your custom view to being the first item. Best of luck! :) – Thomas Nov 26 '10 at 13:39
0

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.

Falmarri
  • 47,727
  • 41
  • 151
  • 191
  • Relative settings (or lack thereof) do not impact a draw order from what I've learned in the past 12 hours. – user432209 Nov 26 '10 at 12:30
  • Umm, I guess it depends on what you mean draw order. I assumed he meant that his views were piling on top of each other – Falmarri Nov 26 '10 at 16:43