Animated Buggy Rotation in API 23 and 24

I have an SVG representation of the FontAwesome icon that I want to give a rotation, ideally entirely in XML.

I created a vector drawable (fa_spinner.xml):

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="256dp"
    android:width="256dp"
    android:viewportWidth="1792"
    android:viewportHeight="1792">

    <path android:fillColor="#18272a"
        android:pathData="M526 1394q0 53-37.5 90.5t-90.5 37.5q-52 0-90-38t-38-90q0-53
            37.5-90.5t90.5-37.5 90.5 37.5 37.5 90.5zm498 206q0 53-37.5 90.5t-90.5
            37.5-90.5-37.5-37.5-90.5 37.5-90.5 90.5-37.5 90.5 37.5 37.5 90.5zm-704-704q0 53-37.5
            90.5t-90.5 37.5-90.5-37.5-37.5-90.5 37.5-90.5 90.5-37.5 90.5 37.5 37.5 90.5zm1202
            498q0 52-38 90t-90 38q-53 0-90.5-37.5t-37.5-90.5 37.5-90.5 90.5-37.5 90.5 37.5 37.5
            90.5zm-964-996q0 66-47 113t-113 47-113-47-47-113 47-113 113-47 113 47 47 113zm1170
            498q0 53-37.5 90.5t-90.5 37.5-90.5-37.5-37.5-90.5 37.5-90.5 90.5-37.5 90.5 37.5 37.5
            90.5zm-640-704q0 80-56 136t-136 56-136-56-56-136 56-136 136-56 136 56 56 136zm530
            206q0 93-66 158.5t-158 65.5q-93 0-158.5-65.5t-65.5-158.5q0-92 65.5-158t158.5-66q92
            0 158 66t66 158z" />
</vector>

And XML rotation (load_spinner.xml):

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:drawable="@drawable/fa_spinner">
</animated-rotate>

Then install it in my view like this:

<ImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:src="@drawable/loading_spinner"/>

The problem is that this seems to behave differently at different API levels:

  • API 22: no problem
  • API 23: SVG flickers twice per revolution
  • API 24: doesn't spin at all
  • API 25: no problem

Is there any XML approach for 23/24 only?

Or is my only option to run a Java / XML way to run animations on a static image?

Same:

//The R.id.static_svg ImageView has src="@drawable/fa_spinner" 
ImageView staticSvg = (ImageView) findViewById(R.id.static_svg);
//R.anim.rotate is a simple rotate animation located in the anim folder
staticSvg.startAnimation(
        AnimationUtils.loadAnimation(this, R.anim.rotate) );
+4
source share

Source: https://habr.com/ru/post/1671082/


All Articles