Android MotionLayout roundPercent只工作一次
我有一个ImageFilterView视图,我正在使用MotionLayout设置动画。它以一个小正方形视图开始,将roundPercent设置为1.0(因此它也是一个圆),隐藏在圆后面,然后设置为全屏正方形的动画。它在第一次设置动画时效果很好,但每隔一段时间就保持为矩形 您可以在此处看到该问题的视频: 我不确定这是ImageFilterView或MotionLayout上的错误,还是我调用了错误的内容。值得一提的是,我不是在转换中使用onClick,而是在类似这样的活动中编程地调用它Android MotionLayout roundPercent只工作一次,android,android-animation,android-motionlayout,Android,Android Animation,Android Motionlayout,我有一个ImageFilterView视图,我正在使用MotionLayout设置动画。它以一个小正方形视图开始,将roundPercent设置为1.0(因此它也是一个圆),隐藏在圆后面,然后设置为全屏正方形的动画。它在第一次设置动画时效果很好,但每隔一段时间就保持为矩形 您可以在此处看到该问题的视频: 我不确定这是ImageFilterView或MotionLayout上的错误,还是我调用了错误的内容。值得一提的是,我不是在转换中使用onClick,而是在类似这样的活动中编程地调用它 imag
imageBorder.setOnClickListener {
if (motionContainer.progress > 0.75)
motionContainer.transitionToStart()
else
motionContainer.transitionToEnd()
}
我的motionScene代码如下所示
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@+id/start"
motion:duration="1000"
motion:motionInterpolator="easeInOut" />
<ConstraintSet android:id="@+id/start">
<Constraint android:id="@id/translucentOverlay">
<Layout
android:layout_width="5dp"
android:layout_height="5dp"
motion:layout_constraintBottom_toBottomOf="@id/imageBorder"
motion:layout_constraintEnd_toEndOf="@id/imageBorder"
motion:layout_constraintStart_toStartOf="@id/imageBorder"
motion:layout_constraintTop_toTopOf="@id/imageBorder" />
<CustomAttribute
motion:attributeName="roundPercent"
motion:customFloatValue="1.0" />
<Motion motion:motionStagger="2" />
</Constraint>
<Constraint android:id="@id/imageBorder">
<Layout
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
<CustomAttribute
motion:attributeName="crossfade"
motion:customFloatValue="0" />
<Motion motion:motionStagger="2" />
</Constraint>
<Constraint android:id="@id/imageBackground">
<Layout
android:layout_width="32dp"
android:layout_height="32dp"
motion:layout_constraintBottom_toBottomOf="@id/imageBorder"
motion:layout_constraintEnd_toEndOf="@id/imageBorder"
motion:layout_constraintStart_toStartOf="@id/imageBorder"
motion:layout_constraintTop_toTopOf="@id/imageBorder" />
<Motion motion:motionStagger="2" />
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint android:id="@id/translucentOverlay">
<Layout
android:layout_width="match_parent"
android:layout_height="match_parent" />
<CustomAttribute
motion:attributeName="roundPercent"
motion:customFloatValue="0.0" />
<Motion motion:motionStagger="2" />
</Constraint>
<Constraint android:id="@id/imageBorder">
<Layout
android:layout_width="88dp"
android:layout_height="88dp"
motion:layout_constraintBottom_toBottomOf="@id/imageBackground"
motion:layout_constraintEnd_toEndOf="@id/imageBackground"
motion:layout_constraintStart_toStartOf="@id/imageBackground"
motion:layout_constraintTop_toTopOf="@id/imageBackground" />
<CustomAttribute
motion:attributeName="crossfade"
motion:customFloatValue="1" />
<Motion motion:motionStagger="2" />
</Constraint>
<Constraint android:id="@id/imageBackground">
<Layout
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginTop="64dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
<Motion motion:motionStagger="2" />
</Constraint>
</ConstraintSet>
我的运动布局如下所示:
<androidx.constraintlayout.motion.widget.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/motionContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
app:layoutDescription="@xml/motion_scene">
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/translucentOverlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/translucent_background_square"/>
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/imageBorder"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="8dp"
android:padding="4dp"
android:src="@drawable/circle_start"
app:altSrc="@drawable/circle_end" />
<ImageView
android:id="@+id/imageBackground"
android:layout_width="32dp"
android:layout_height="32dp"
android:importantForAccessibility="no"
android:tint="@color/primaryDarkColor"
app:srcCompat="@drawable/circle_opaque" />
</androidx.constraintlayout.motion.widget.MotionLayout>
第一次之后它就停止工作了,这真让人恼火。很长一段时间以来,我一直在尝试解决这个由圆到方的问题,我认为我终于找到了解决方案,但似乎没有 在进行更多的摆弄之后,这似乎是ImageFilterView中的一个错误,如果将roundPercent设置为0.0,视图将在其余时间保持矩形。我想这是一个除以0或类似的错误的问题。我已经向谷歌开发者报告了这个问题,希望很快能得到解决
同时,您可以通过将percentRound设置为0.000001来解决这个问题,从而绕过被零除的错误 您是否尝试过在每次成功展开/折叠后清除动画?@YunusKulyyev是的,我只是通过向transitionListener的onTransitionCompleted方法添加clearAnimation()调用来尝试。这并不能解决问题。我还尝试在运动场景中通过onClick而不是通过编程实现单击操作,但这也没有解决问题:(@YunusKulyyev ok奇怪的事情,如果我把它改为roundPercent=0.1而不是roundPercent=0.0,它是双向的…为什么填充屏幕/去矩形会破坏它?当你尝试用0.0做数学时,可能会有一些算术错误?@YunusKulyyev这是一个很好的猜测。我刚刚在IssueTracker上提交了一个bug,希望它会是修正了!但我可以通过将end roundPercent设置为0.000001来解决这个问题