Android动画旋转属性不工作
我正在尝试仅使用xml制作自定义动画progressBar 我用圆创建了图层列表,但是当我对所有具有不同属性的圆使用标记动画旋转时,它们仍然在做同样的事情 如何为列表中的每个项目制作不同的旋转动画Android动画旋转属性不工作,android,xml,android-studio,kotlin,Android,Xml,Android Studio,Kotlin,我正在尝试仅使用xml制作自定义动画progressBar 我用圆创建了图层列表,但是当我对所有具有不同属性的圆使用标记动画旋转时,它们仍然在做同样的事情 如何为列表中的每个项目制作不同的旋转动画 <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/first"> <an
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/first">
<animated-rotate
android:duration="2000"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="1"
android:toDegrees="-360">
<shape
android:layout_width="match_parent"
android:layout_height="match_parent"
android:innerRadius="100dp"
android:shape="oval">
<padding
android:bottom="3dp"
android:left="3dp"
android:right="3dp"
android:top="3dp" />
<stroke
android:width="2dp"
android:color="@color/colorPrimary"
android:dashWidth="60dp"
android:dashGap="60dp" />
<size
android:width="150dp"
android:height="150dp" />
</shape>
</animated-rotate>
</item>
<item>
<animated-rotate
android:duration="300"
android:fromDegrees="0"
android:interpolator="@android:anim/cycle_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toDegrees="360">
<shape
android:layout_width="match_parent"
android:layout_height="match_parent"
android:innerRadius="100dp"
android:shape="oval">
<padding
android:bottom="3dp"
android:left="3dp"
android:right="3dp"
android:top="3dp" />
<stroke
android:width="2dp"
android:color="@color/colorSecondary"
android:dashWidth="50dp"
android:dashGap="50dp" />
</shape>
</animated-rotate>
</item>
</layer-list>
一种解决方案是创建一个带有动画的文件。在代码内部,使用线程设置动画开始之间的延迟 比如说,
Thread t = new Thread(){
public void run(){
t.sleep(500);
Animation rotation = AnimationUtils.loadAnimation(StartActivity.this, R.anim.rotate);
view.startAnimation(rotation);
t.sleep(500);
Animation rotation = AnimationUtils.loadAnimation(StartActivity.this, R.anim.rotate);
view2.startAnimation(rotation);
t.sleep(500):
Animation rotation = AnimationUtils.loadAnimation(StartActivity.this, R.anim.rotate);
view3.startAnimation(rotation);
..... (This would go on until you started the animation for all the circles)
}
}
t.start();