views:

11

answers:

1

How can I achieve the following layout in Android?

What I would like, is to have the 3 blue boxes top aligned in their view, and then I'd like to have the red box centered underneath the blue boxes, but so that when I animate the red box up, it slides underneath the blue box.

I have tried placing the blue and red boxes in different layouts, but as soon as I animate the red box up, if it goes outside the border of its layout, it disappears (I don't want the red box's layout to clip the red box, I want the red box to slide under the blue box so that the blue box occludes the red box.)

I have also managed to create this layout using a series of nested layouts, but because of the draw order, the red box always appears on top of the blue box. I attempted to use the bringToFront() method, but I found out that this only works on sibling views within the same layout. Unfortunately I can't get this type of layout while keeping all 4 views within the same layout. Any suggestions? (also, if anyone has better suggestions for the title of this question I'm all ears)

alt text

+1  A: 

Hi, try to use the RelativeLayout. If you know the height of the blue box, you can draw the red box always first and add the blue box later in your layout which will make sure, that the blue box is always on top of the red one.

You could also consider using a SurfaceView where you can order you items easily and without any xml definition...

WarrenFaith
Hey that worked better than I thought. I had tried the RelativeLayout before with no success but trying it again I was able to figure it out. While I don't believe there is any way to center the red box underneath the blue box (if the views are not the same width), what I did was set the red box below the blue box, and then toRightOf the the leftmost blue box, and just made sure the red and blue views were the same width. To fix the z order issue when I run the animation of the red box moving up, I just send the blue box to the front using bringToFront(). Voila! Thanks WarrenFaith
justinl