我正在使用一个视图切换器 http://developer.android.com/intl/fr/reference/android/widget/ViewSwitcher.html这让我可以轻松地在两个不同的内置动画的列表标题之间来回翻转。
然而,问题是两个视图的高度差异很大,并且 ViewSwitcher 似乎layout_height="wrap_content"
,测量两个孩子的身高,并将两个身高中较大的一个作为自己的身高。这会导致在显示较小视图时,在其正下方出现大量不需要的空白区域。
我理解为什么这是理想的 ViewSwitcher 行为,但不是理想的“我的应用程序”行为。
Example:
假设视图 A 的高度为 50dp,视图 B 的高度为 100dp,并且两者都作为子项添加到 ViewSwitcher。即使显示视图 A,ViewSwitcher 的高度也始终为 100dp。
我想要的是能够在 A 和 B 之间切换,并使 ViewSwitcher 缩小或增大以适合当前显示的视图。我怎样才能做到这一点?
Set the measureAllChildren
属性上的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">
欲了解更多信息,请参阅文档 http://developer.android.com/reference/android/widget/FrameLayout.html#setMeasureAllChildren%28boolean%29.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)