如何在MotionLayout过渡期间平滑地更改视图的角点半径



我想在转换期间更改约束布局中的可绘制角半径,但我还没有找到如何使用xml来实现这一点,因为CustomAttribute标记只支持可绘制颜色作为值。

<Constraint
android:id="@+id/layout_player"
android:layout_width="0dp"
android:layout_height="42dp"
android:background="@drawable/bg_player_control_part"
motion:layout_constraintBottom_toBottomOf="@+id/layout_parent_audio_player_card"
motion:layout_constraintEnd_toStartOf="@+id/tv_time_audio_small"
motion:layout_constraintStart_toEndOf="@+id/img_photo_audio_news_small">
<CustomAttribute
motion:attributeName="background"
motion:customColorDrawableValue="@drawable/bg_player_control_part" />
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/layout_player"
android:layout_width="0dp"
android:layout_height="42dp"
motion:layout_constraintBottom_toBottomOf="@+id/layout_parent_audio_player_card"
motion:layout_constraintEnd_toStartOf="@+id/tv_time_audio_small"
motion:layout_constraintStart_toEndOf="@+id/img_photo_audio_news_small">
<CustomAttribute
motion:attributeName="background"
motion:customColorDrawableValue="@color/color_bg_audio_player" />
</Constraint>
</ConstraintSet>```

一般情况下,MotionLayout仅对视图和视图方法进行操作。绘画不是风景。但是你可以用两种方法来做你需要的事情。

  1. 创建视图的子类并添加设置角的方法半径
  2. 我们在库中有一些视图,可以让您对其拐角半径进行操作。ImageFilterButton,ImageFilterView&运动按钮

然后可以使用调用它们

<CustomAttribute motion:attributeName="round" motion:customDimension="4dp"/>
<CustomAttribute motion:attributeName="roundPercent" motion:customFloatValue="0.5"/>

分别调用setRound(…(和setRoundPercent(..(

最新更新