views:

391

answers:

2

I have a Gallery widget and 2 imageviews, one on the left of the screen and one on the right. I want the imageview and gallery to stay on the same line, but if there is an overlap, the imageview's z-index should be higher then the gallery's.

The problem is the imageview appears underneath the gallery item. I've had a look in the android doc, but can't find the solution. My XML file is below (For some reason, the opening Root relative layout's opening and closing tag isn't showing up):

<ImageView
        android:id="@+id/greenarrow_right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/green_arrow_right"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dip"
        android:layout_marginTop="10dip"
/>  

<ImageView
        android:id="@+id/greenarrow_left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/green_arrow_left"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dip"
        android:layout_marginTop="10dip"
/>  
<Gallery 
    android:id="@+id/gallery"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:spacing="3dip"         
/>

  <!-- more elements here -->
A: 

Did you try ViewParent.BringChildToFront(myImageView)?

RickNotFred
+1  A: 

The last child of the RelativeLayout will be on top. If your layout is as depicted above, that means the Gallery will be on top of the second ImageView. Change your XML and the RelativeLayout rules to make the second ImageView appear after the Gallery in the XML.

CommonsWare
Excellent, that solved it. Does the documentation mention this behaviour? I just checked and it mentions that when items depend on others, make sure the others appear first.
Al