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

好久不见. 提交于 2019-12-09 14:29:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5466537/how-to-get-viewswitcher-to-wrap-only-the-currently-displayed-view-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!