android - Android动画旋转属性不起作用
问题描述
我正在尝试仅使用 xml 制作自定义动画进度条。
我用圆圈制作了图层列表,但是当我对具有不同属性的所有圆圈使用标签动画旋转时,它们仍然在做同样的事情。
我怎样才能为这个列表中的每个项目制作不同的旋转动画?
<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();
推荐阅读
- android - 找不到 com.zendesk:support-providers:5.0.2
- python - Jupyter notebook 内核不断需要重启
- c# - 如何在 C# 数组中查找和显示特定值
- c# - 进程 Azure AD B2C 自定义策略用于散列数据
- r - check_rhub 正在尝试安装 BiocManager 失败
- spring-boot - 如何将流量重新路由到 ip 到特定端口以显示网站
- reactjs - Jest Globals 收到“不是函数”错误,没有 Globals 可以正常工作
- python - 在字符串中执行python代码并将其存储到变量中
- node.js - Docusign - 如何为多个用户集成 docusign,每个用户都有不同的 docusign 凭据和多个客户
- javascript - 如何在基于反应js的id中获取api中的数据