如何在使用MotionLayout时将色调指定为ImageView上的自定义属性



使用MotionLayout时,如何将imageView的色调指定为自定义属性。目前,我只能在MotionScenexml文件中指定自定义背景颜色:

<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/imageView"
android:layout_width="180dp"
android:layout_height="180dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintVertical_bias="0.75"
motion:srcCompat="@drawable/ic_android_black_24dp" >
<CustomAttribute
motion:attributeName="backgroundColor"
motion:customColorValue="#9999FF" />
</Constraint>
</ConstraintSet>
请注意,您使用的是backgroundColor,但属性是android:background。对于tint,您应该写:
<CustomAttribute
motion:attributeName="ColorFilter"
motion:customColorValue="#9999FF" />

据我所知,CustomAttribute的特性使用反射,而不是xml等中的属性。请记住,所有自定义属性都使用反射。

您可以使用ColorFilter。

<CustomAttribute
motion:attributeName="colorFilter"
motion:customColorValue="@color/your_tint_color" />

由于tint采用颜色值,因此它应该与backgroundColor几乎相同

<CustomAttribute motion:attributeName="tint" motion:customColorValue="@color/your_tint_color" />

最新更新