Eme*_*kpo 5 android android-constraintlayout
使用 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>
Run Code Online (Sandbox Code Playgroud)
ylu*_*lus 11
请注意,您正在使用backgroundColor但属性是android:background. 因为tint你应该写:
<CustomAttribute
motion:attributeName="ColorFilter"
motion:customColorValue="#9999FF" />
Run Code Online (Sandbox Code Playgroud)
据我所知,CustomAttribute使用反射的功能而不是来自 xml 等的属性。请记住所有自定义属性。
您可以使用ColorFilter。
<CustomAttribute
motion:attributeName="colorFilter"
motion:customColorValue="@color/your_tint_color" />
Run Code Online (Sandbox Code Playgroud)
小智 -4
由于色调采用颜色值,因此它应该几乎与backgroundColor
<CustomAttribute
motion:attributeName="tint"
motion:customColorValue="@color/your_tint_color" />