我有一个LinearLayout,我在父LinearLayout中应用了android:animateLayoutChanges="true"。当用户点击切换按钮时,LinearLayout会“折叠”(我通过编程将视图的可见性设置为LinearLayout.GONE),再次点击它时,通过编程将可见性设置回LinearLayout.VISIBLE来展开。
折叠和展开的动画效果是正确的。
然而,在折叠动画完成之前,任何位于可折叠/可展开LinearLayout下方的项目都会弹回到顶部。这些弹回的项目不在具有animateLayoutChanges设置为true的父级中,我认为没有办法将它们放入其中。
以下是我的布局层次结构(我没有提及属性以使其简短):
我意识到,如果我在具有
那么还有其他的解决方法吗?
折叠和展开的动画效果是正确的。
然而,在折叠动画完成之前,任何位于可折叠/可展开LinearLayout下方的项目都会弹回到顶部。这些弹回的项目不在具有animateLayoutChanges设置为true的父级中,我认为没有办法将它们放入其中。
以下是我的布局层次结构(我没有提及属性以使其简短):
<!-- Top most LinearLayout-->
<LinearLayout>
<!-- LinearLayout containing android:animateLayoutChanges="true"-->
<LinearLayout>
<!-- RelativeLayout containing button to toggle LinearLayout visibility below-->
<RelativeLayout>
</RelativeLayout>
<!-- LinearLayout that has its visibility toggled -->
<LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
整个布局是通过编程方式插入到另一个 LinearLayout
中(如下所示):
<LinearLayout
android:id="@+id/form_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- This is where the previous XML layout containing the toggle-able LinearLayout
is inserted programmatically. -->
<!-- This button snaps back up to the top before the animation is complete. -->
<Button />
</LinearLayout>
我意识到,如果我在具有
animateLayoutChanges
属性的 LinearLayout
上添加弹出 Button
,问题就会得到解决。但是,由于几个原因,这不是一个可行的选择。那么还有其他的解决方法吗?