Search code examples
androidandroid-layoutandroid-2.3-gingerbread

Resizing a view to overlap half the screen


I'm looking to resize a View that starts out as something like 200px wide by 100px high then "expands" to fill half the screen when it's tapped. All the views behind it should stay in the same position. I just want said view to expand to fill up half the screen, overlapping anything that's currently on-screen.

What's the most elegant way to do this? I spent a lot of time setting up my layout and I don't really want to change it...

This is how I intend to implement this:

  • Create a RelativeLayout that will have two children: the root view of the current hierarchy and second, new RelativeLayout.
  • Remove the resizeView from the original hierarchy, replacing it with a placeholder view so that things don't move around in the original hierarchy.
  • Add the resizeView to the second RelativeLayout and expand it to half the screen.
  • When the resizeView wants to collapse, remove it from the second RelativeLayout.
  • Remove the placeholder from the original view hierarchy. Put the resizeView back in its original place.
  • Restore the original view hierarchy.

Does this process makes sense? I feel like it's a little convoluted. Is there a better way?


Solution

  • You can encapsulate your current layout in a frame layout, and add another frame on top of this one containing the moving view.

    Then you can just animate freely the moving image in its on layer of layout, and it will go over what's under :)