Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ViewSwitcher to wrap only the currently displayed view height?

I'm using a ViewSwitcher that lets me easily flip back and forth between two different List Headers with Animations built in.

However, the problem is the two views are of greatly varying height and it appears that the ViewSwitcher with layout_height="wrap_content", measures both children and takes the greater of the two heights as its own. This results in a large amount of unwanted blank space immediately below the smaller view when it is showing.

I understand why this is desired ViewSwitcher behavior, but it is NOT desired My App behavior.

Example:
Say View A is 50dp tall and View B is 100dp tall and both are added as children to the ViewSwitcher. The ViewSwitcher always is 100dp tall even with View A showing.

What I want is to be able to switch between A and B and have the ViewSwitcher shrink or grow to fit whichever view is currently displayed. How can I do this?

like image 263
CodeFusionMobile Avatar asked Mar 29 '11 00:03

CodeFusionMobile


1 Answers

Set the measureAllChildren attribute on the ViewSwitcher to false.

<ViewSwitcher
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:measureAllChildren="false">

For more info see documentation.

like image 93
balazsbalazs Avatar answered Sep 30 '22 19:09

balazsbalazs