I added a ViewSwitcher to a LinearLayout, which has two views of different height, However it seems the ViewSwitcher is occupying space of the biggest of the views, rather than arranging itself. Is this how it should be?
What to do in the other case? I was trying to create an accordion, where the title panel, when clicked grows in size
ViewSwitcher is a sub-class of ViewAnimator and is used for switching between views which bring different views to customers. It is an element of the transition widget which helps us to add transitions on the views. We can use that to animate a view on the screen.
In Android, ViewSwitcher is a sub class of ViewAnimator that is used for switching between views. It is an element of transition widget which helps us to add transitions on the views. It is mainly useful to animate a view on screen.
The default behavior of ViewSwitcher, as inherited by ViewAnimator, is to consider all child views on layout, which will result in the ViewSwitcher occupying the space of the largest child.
To change this, all you need to do is to set the MeasureAllChildren flag to false. This will make the layout pass ignore the child view that is currently hidden. Set this flag e.g. in the onCreate method of the activity, e.g.:
ViewSwitcher switcher = (ViewSwitcher)findViewById(R.id.ViewSwitcher); switcher.setMeasureAllChildren(false);
XML example:
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/viewSwitcher" android:measureAllChildren="false"> </ViewSwitcher>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With