我在 NestedScrollView 中有一个 MotionLayout:
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_content"
android:layout_width="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/content_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
app:layoutDescription="@xml/main_scene">
<View 1>
<View 2>
<View 3>
</androidx.constraintlayout.motion.widget.MotionLayout>
我的状态 1 仅显示 View 1。
我的状态 2 仅显示 View 2。
我的状态 3 显示 View 1 + View 2( View 1 下方)+ View 3( View 2 下方)
由于状态 3 垂直附加多个 View ,因此它是垂直方向最长的。
但是,我只能向下滚动到为状态 1 和状态 2 设置的量。它不会重置 ScrollView 内的高度。
我做错了什么吗?
我在 onTransitionCompleted() 中尝试了以下操作:
scroll_content.getChildAt(0).invalidate()
scroll_content.getChildAt(0).requestLayout()
scroll_content.invalidate()
scroll_content.requestLayout()
他们没有解决我的问题。
最佳答案
添加motion:layoutDuringTransition="honorRequest"
里面<Transition>
在你的layoutDescription
XML 文件修复了该问题。
这已添加到 ConstraintLayout
版本 2.0.0-beta4
关于android - ScrollView内部的MotionLayout在状态改变后不更新高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56568266/