我有一个FontAwesome图标的SVG表示,我想给它一个旋转,理想情况下完全是用XML。
我已经创建了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>
XML旋转(loading_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>
然后在我的视图中设置它:
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/loading_spinner"/>
问题在于,在不同的API级别中,这似乎表现得不同:
是否有任何XML仅适用于23/24?
或者是我唯一选择在静态图像上启动动画的Java / XML方式吗?
像这样:
//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) );