Das ist mein build.gradleKann nicht AnimatedVectorDrawableCompat in Nougat werfen
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
vectorDrawables.useSupportLibrary = true
}
und ein Teil des Layouts
<ImageView
android:id="@+id/recents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:scaleType="fitCenter"
app:srcCompat="@drawable/anim_test"/>
und die Klasse Besetzung:
val np = convertView.findViewById<ImageView>(R.id.recents)
val anim = np.drawable as AnimatedVectorDrawableCompat
Dies funktioniert wie erwartet auf Lolipop (sdk 21), scheitert aber am Nougat-Sprichwort:
android.graphics.drawable.AnimatedVectorDrawable cannot be cast to android.support.graphics.drawable.AnimatedVectorDrawableCompat
Was ich nicht bekomme ist, warum es eine AnimatedVectorDrawableCompat auf SDK Ebene 21 überhaupt zurückgibt, wenn AnimatedVectorDrawable bereits vom System unterstützt wird. Und warum gibt es den AnimatedVectorDrawable in Nougat trotz Angabe vectorDrawables.useSupportLibrary = true
zurück.
gleiche Problem mit Support-Bibliothek 26.0.1. Gelöst durch eine Problemumgehung: Eine Bedingung zur Laufzeit - Sie müssen AnimatedVectorDrawable für Lollipop und höher und AnimatedVectorDrawableCompat für vorherigen Lollipop umwandeln. – Fllo