我想在转换期间更改约束布局中的可绘制角半径,但我还没有找到如何使用 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 只对 View 和 View 的方法进行操作。 可绘制对象不是视图。 但你可以通过两种方式做你需要的事情。
然后可以使用以下方式调用它们:
<CustomAttribute motion:attributeName="round" motion:customDimension="4dp"/>
<CustomAttribute motion:attributeName="roundPercent" motion:customFloatValue="0.5"/>
分别调用 setRound(...) 和 setRoundPercent(..)
如果您查看文档
CustomAttribute
支持以“set”开头的所有属性,那么棘手的部分以及您可能为此苦苦挣扎的原因是,设置 cornerRadius
的编程方法是 CardView.setRadius(float value)
,因此将其设置为您的 MotionScene xml 正在添加:
在你的开始约束中添加->
<CustomAttribute
motion:attributeName="radius"
motion:customFloatValue="0f" />
最后约束->
<CustomAttribute
motion:attributeName="radius"
motion:customFloatValue="38f" />