android - ScrollView内部的MotionLayout在状态改变后不更新高度

标签 android android-scrollview android-motionlayout

我在 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/

相关文章:

android - com.google.android.gms.internal.firebase-perf.zzw 上的 NoClassDefFoundError

Android - Horizo​​ntalScrollView - 获取焦点 View (或它的索引)

android - 同一个 Scroll View 中的 Image 和 ExpandableListView

带有 MotionLayout 的 Android 折叠工具栏 - 当 RecyclerView 为空/不可滚动时禁用运动

android - 带有滑动手势的运动布局 + SwipeRefreshLayout + RecyclerView 错误向上滚动的错误行为

android - EditText 提示在 inputType ="textpassword"时显示额外的空格

android - 如何在Android中限制显示列表

c# - 如何从具有不同内容的单个 Android 应用程序创建多个应用程序

android - ScrollView 在约束布局内不起作用

android - 如何在 Activity 旋转时保存/恢复 MotionLayout 的状态