对于一个我正在使用MotionLayout的项目,除一件小事情外,其他所有组件都工作正常且流畅。当我打开应用程序并按屏幕上的某个位置时,有时布局会跳到未定义状态。
我定义的状态是: -该应用以“白色”背景开头 -向右滑动时,将显示蓝色背景的框架布局 -向上滑动时,将显示红色背景的框架布局,隐藏所有其他imageViews
应用程序在按屏幕某处时所处的状态 -出现红色背景,所有imageViews可见。
我一直在寻找导致这种情况发生的原因,我想这是一个错误(因为它仍然处于alpha状态),但想征询他人的意见。
该代码将被附加以相当容易地重现它。
主要布局:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/fl_forUnity"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="match_parent"
android:alpha="1"
tools:ignore="UnusedAttribute"/>
<androidx.constraintlayout.motion.widget.MotionLayout
app:layoutDescription="@xml/scene_motion"
android:id="@+id/topMotionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/backgroundView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View
android:id="@+id/ivBottomAnchor"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<FrameLayout
android:id="@+id/flBottom"
app:layout_constraintTop_toBottomOf="@id/ivBottomAnchor"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<View
android:id="@+id/ivLeftAnchor"
android:layout_width="1dp"
android:layout_height="match_parent"/>
<FrameLayout
android:id="@+id/flLeft"
app:layout_constraintEnd_toStartOf="@id/ivLeftAnchor"
android:layout_width="300dp"
android:layout_height="match_parent"/>
<View
android:id="@+id/ivRightAnchor"
android:layout_width="1dp"
android:layout_height="match_parent"/>
<FrameLayout
android:id="@+id/flRight"
app:layout_constraintStart_toEndOf="@id/ivRightAnchor"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="0dp"
android:layout_height="match_parent"/>
<ImageView
android:layout_width="32dp"
android:src="@drawable/ic_message"
android:layout_height="32dp"
tools:tint="@color/colorGreen_200"
android:id="@+id/fabStartButton"/>
<ImageView
android:id="@+id/middleButton"
tools:tint="@color/colorGreen_200"
android:layout_width="64dp"
android:src="@drawable/ic_circle"
android:layout_height="64dp"/>
<ImageView
android:id="@+id/bottomButton"
tools:tint="@color/colorGreen_200"
android:layout_width="28dp"
android:src="@drawable/ic_message"
android:layout_height="28dp"/>
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
tools:tint="@color/colorGreen_200"
android:src="@drawable/ic_adb"
android:id="@+id/fabEndButton"/>
<ImageView
android:src="@drawable/ic_orb"
android:id="@+id/ivOrb"
tools:tint="@color/colorGreen_200"
android:layout_width="6dp"
android:layout_height="6dp"/>
</androidx.constraintlayout.motion.widget.MotionLayout>
动作布局:
<MotionScene
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
android:id="@+id/SwipeUp"
motion:constraintSetStart="@+id/beginning"
motion:constraintSetEnd="@+id/endAtTop">
<OnSwipe
motion:dragDirection="dragUp"
motion:touchAnchorId="@id/ivBottomAnchor"
motion:touchAnchorSide="top"/>
<KeyFrameSet>
<KeyAttribute
android:alpha="0"
motion:framePosition="15"
motion:target="@id/bottomButton"/>
<KeyAttribute
android:alpha="0"
motion:framePosition="15"
motion:target="@id/fabStartButton"/>
<KeyAttribute
android:alpha="0"
motion:framePosition="15"
motion:target="@id/middleButton"/>
<KeyAttribute
android:alpha="0"
motion:framePosition="15"
motion:target="@id/fabEndButton"/>
<KeyAttribute
motion:target="@id/backgroundView">
<CustomAttribute
motion:attributeName="backgroundColor"
motion:customColorValue="#B71C1C"/>
</KeyAttribute>
</KeyFrameSet>
</Transition>
<Transition
android:id="@+id/SwipeLeft"
motion:constraintSetStart="@+id/beginning"
motion:constraintSetEnd="@+id/endRighty">
<OnSwipe
motion:dragDirection="dragLeft"
motion:touchAnchorId="@id/ivRightAnchor"
motion:touchAnchorSide="top"/>
</Transition>
<Transition
android:id="@+id/SwipeRight"
motion:constraintSetStart="@+id/beginning"
motion:constraintSetEnd="@+id/endLefty">
<OnSwipe
motion:dragDirection="dragRight"
motion:touchAnchorId="@id/ivLeftAnchor"
motion:touchAnchorSide="top"/>
<KeyFrameSet>
<KeyAttribute
motion:target="@id/backgroundView">
<CustomAttribute
motion:attributeName="backgroundColor"
motion:customColorValue="#0D47A1"/>
</KeyAttribute>
</KeyFrameSet>
</Transition>
<!--TODO: pressing on the bottombutton, go to bottom screen-->
<ConstraintSet android:id="@+id/beginning">
<Constraint
android:id="@+id/backgroundView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"/>
<Constraint
android:id="@+id/tbMain"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"/>
<Constraint
android:id="@+id/ivBottomAnchor"
motion:layout_constraintBottom_toBottomOf="parent"
android:layout_height="1dp"
android:layout_width="match_parent"/>
<Constraint
android:id="@+id/flBottom"
motion:layout_constraintTop_toBottomOf="@id/ivBottomAnchor"
motion:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/ivLeftAnchor"
motion:layout_constraintStart_toStartOf="parent"
android:layout_height="match_parent"
android:layout_width="1dp"/>
<Constraint
android:id="@+id/flLeft"
motion:layout_constraintEnd_toStartOf="@id/ivLeftAnchor"
android:layout_width="300dp"
android:layout_marginEnd="10dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/tbMain"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/ivRightAnchor"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_height="match_parent"
android:layout_width="1dp"/>
<Constraint
android:id="@+id/flRight"
android:layout_width="0dp"
motion:layout_constraintStart_toEndOf="@id/ivRightAnchor"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/tbMain"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/fabStartButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginBottom="32dp"
android:layout_marginStart="32dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/middleButton"
android:layout_width="78dp"
android:layout_height="78dp"
motion:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="72dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/bottomButton"
android:layout_marginBottom="32dp"
android:layout_width="28dp"
android:layout_height="28dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/fabEndButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginBottom="32dp"
android:layout_marginEnd="32dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"/>
<Constraint
android:id="@+id/ivOrb"
android:layout_width="6dp"
android:layout_height="6dp"
android:visibility="gone"
android:alpha="0"
android:layout_marginTop="8dp"
motion:layout_constraintTop_toBottomOf="@id/fabStartButton"
motion:layout_constraintStart_toStartOf="@id/middleButton"
motion:layout_constraintEnd_toEndOf="@id/middleButton"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/endAtTop">
<Constraint
android:id="@+id/backgroundView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="1"/>
<Constraint
android:id="@+id/tbMain"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"/>
<Constraint
android:id="@+id/ivBottomAnchor"
android:layout_height="1dp"
motion:layout_constraintTop_toBottomOf="@id/tbMain"
android:layout_width="match_parent"/>
<Constraint
android:id="@+id/flBottom"
motion:layout_constraintTop_toBottomOf="@id/ivBottomAnchor"
motion:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/ivLeftAnchor"
motion:layout_constraintStart_toStartOf="parent"
android:layout_height="match_parent"
android:layout_width="1dp"/>
<Constraint
android:id="@+id/flLeft"
motion:layout_constraintEnd_toStartOf="@id/ivLeftAnchor"
android:layout_width="300dp"
android:layout_marginEnd="10dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/tbMain"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/ivRightAnchor"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_height="match_parent"
android:layout_width="1dp"/>
<Constraint
android:id="@+id/flRight"
android:layout_width="0dp"
motion:layout_constraintStart_toEndOf="@id/ivRightAnchor"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/tbMain"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/fabStartButton"
android:layout_width="26dp"
android:layout_height="26dp"
android:alpha="0"
android:layout_marginBottom="32dp"
android:layout_marginStart="80dp"
android:translationY="-100dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/middleButton"
android:layout_width="52dp"
android:translationY="-100dp"
android:alpha="0"
android:layout_height="52dp"
motion:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="38dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/bottomButton"
android:translationY="-100dp"
android:layout_width="26dp"
android:layout_height="26dp"
android:alpha="0"
motion:layout_constraintTop_toBottomOf="@id/middleButton"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/fabEndButton"
android:layout_width="26dp"
android:translationY="-100dp"
android:alpha="0"
android:layout_height="26dp"
android:layout_marginBottom="32dp"
android:layout_marginEnd="80dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"/>
<Constraint
android:id="@+id/ivOrb"
android:visibility="gone"
android:translationY="-100dp"
android:layout_width="6dp"
android:alpha="0"
android:layout_height="6dp"
android:layout_marginTop="8dp"
motion:layout_constraintTop_toBottomOf="@id/fabStartButton"
motion:layout_constraintStart_toStartOf="@id/middleButton"
motion:layout_constraintEnd_toEndOf="@id/middleButton"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/endRighty">
<Constraint
android:id="@+id/backgroundView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"/>
<Constraint
android:id="@+id/tbMain"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"/>
<Constraint
android:id="@+id/ivBottomAnchor"
android:layout_height="1dp"
motion:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"/>
<Constraint
android:id="@+id/flBottom"
motion:layout_constraintTop_toBottomOf="@id/ivBottomAnchor"
motion:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/ivLeftAnchor"
motion:layout_constraintStart_toStartOf="parent"
android:layout_height="match_parent"
android:layout_width="1dp"/>
<Constraint
android:id="@+id/flLeft"
motion:layout_constraintEnd_toStartOf="@id/ivLeftAnchor"
android:layout_width="300dp"
android:layout_marginEnd="10dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/tbMain"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/ivRightAnchor"
motion:layout_constraintStart_toStartOf="parent"
android:layout_height="match_parent"
android:layout_width="1dp"/>
<Constraint
android:id="@+id/flRight"
motion:layout_constraintStart_toEndOf="@id/ivRightAnchor"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/tbMain"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/fabStartButton"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_marginBottom="32dp"
android:layout_marginStart="80dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/middleButton"
android:layout_width="52dp"
android:layout_height="52dp"
motion:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="38dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/bottomButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:alpha="0"
motion:layout_constraintTop_toBottomOf="@id/middleButton"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/fabEndButton"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_marginBottom="32dp"
android:layout_marginEnd="80dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"/>
<Constraint
android:id="@+id/ivOrb"
android:layout_width="6dp"
android:layout_height="6dp"
android:layout_marginTop="8dp"
motion:layout_constraintTop_toBottomOf="@id/fabEndButton"
motion:layout_constraintStart_toStartOf="@id/fabEndButton"
motion:layout_constraintEnd_toEndOf="@id/fabEndButton"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/endLefty">
<Constraint
android:id="@+id/backgroundView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="1"/>
<Constraint
android:id="@+id/tbMain"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"/>
<Constraint
android:id="@+id/ivBottomAnchor"
android:layout_height="1dp"
motion:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"/>
<Constraint
android:id="@+id/flBottom"
motion:layout_constraintTop_toBottomOf="@id/ivBottomAnchor"
motion:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/ivLeftAnchor"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_height="match_parent"
android:layout_width="1dp"/>
<Constraint
android:id="@+id/flLeft"
motion:layout_constraintEnd_toStartOf="@id/ivLeftAnchor"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/tbMain"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/ivRightAnchor"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_height="match_parent"
android:layout_width="1dp"/>
<Constraint
android:id="@+id/flRight"
android:layout_width="0dp"
motion:layout_constraintStart_toEndOf="@id/ivRightAnchor"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/tbMain"
android:layout_height="0dp"/>
<Constraint
android:id="@+id/fabStartButton"
android:layout_width="26dp"
android:layout_height="26dp"
android:alpha="0"
android:layout_marginBottom="32dp"
android:layout_marginStart="80dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/middleButton"
android:layout_width="52dp"
android:layout_height="52dp"
android:alpha="0"
motion:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="38dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/bottomButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:alpha="0"
motion:layout_constraintTop_toBottomOf="@id/middleButton"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"/>
<Constraint
android:id="@+id/fabEndButton"
android:layout_width="26dp"
android:layout_height="26dp"
android:alpha="0"
android:layout_marginBottom="32dp"
android:layout_marginEnd="80dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"/>
<Constraint
android:id="@+id/ivOrb"
android:alpha="0"
android:layout_width="6dp"
android:layout_height="6dp"
android:layout_marginTop="8dp"
motion:layout_constraintTop_toBottomOf="@id/fabStartButton"
motion:layout_constraintStart_toStartOf="@id/fabStartButton"
motion:layout_constraintEnd_toEndOf="@id/fabStartButton"/>
</ConstraintSet>
答案 0 :(得分:0)
解决方案是等待motionLayout的新版本。在那个RC中(我认为是RC3)是关于可见性状态等的错误。从下一个RC(RC4)开始,此问题已解决,并且按预期工作。