Issue
Was observed a WONDERFUL issue when using a Vector Drawable in a RotateDrawble
, two times per each full cycle (0° to 360° / level: 0 → 10000
)! First about 90° (level: 2500
) and another about 270° (level: 7500
). See below test:
My RotateDrawable
(File Name: rotatable_info.xml
):
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360"
android:drawable="@drawable/ic_info_black_24dp" >
</rotate>
My layout design:
<LinearLayout android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<ImageView style="@style/style" android:id="@+id/ImageView00" />
<ImageView style="@style/style" android:id="@+id/ImageView01" />
<ImageView style="@style/style" android:id="@+id/ImageView02" />
...
<ImageView style="@style/style" android:id="@+id/ImageView19" />
</LinearLayout>
The referenced style:
<style name="style">
<item name="android:layout_width">32dp</item>
<item name="android:layout_height">32dp</item>
<item name="android:src">@drawable/rotatable_info</item>
</style>
My code:
int n = -550;
((RotateDrawable) this.<ImageView>findViewById(R.id.ImageView00).getDrawable()).mutate().setLevel(n+=550);
((RotateDrawable) this.<ImageView>findViewById(R.id.ImageView01).getDrawable()).mutate().setLevel(n+=550);
...
((RotateDrawable) this.<ImageView>findViewById(R.id.ImageView18).getDrawable()).mutate().setLevel(n+=550);
((RotateDrawable) this.<ImageView>findViewById(R.id.ImageView19).getDrawable()).mutate().setLevel(n+=550);
(.mutate()
is needed for acting rotation independently for each ImageView
. It has not an effect on the main issue.)
My result (!?!?):
ic_info_black_24dp.xml
: (Generated by Vector Asset Studio in Android Studio ... I also tested some other SVGs. There is no problem for raster drawables.)
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
</vector>
Solution
Seems to be a bug. vectorDrawables.useSupportLibrary = true
solved the problem.
See "Vector drawables backward compatibility solution" section of below page for details:
https://developer.android.com/guide/topics/graphics/vector-drawable-resources
Answered By - Mir-Ismaili
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.