如何借助touch事件在Android上的活动中旋转图像轮?我需要一些指南或任何教程的链接.
解决方法:
这通常需要几块.这就是我在其中一个应用程序中执行此操作的方式. *注意:这不是一个平滑的轮子,因为它在顶部开始和停止(这是有意的).您可以在dev site上查找有关Animation的更多信息.
具有图像的主要XML:
android:id="@+id/anim_example"
android:src="@drawable/loading_circle"
android:layout_width="30sp"
android:layout_height="30sp"
android:onClick="RunAnimation" />
这是运行动画的代码部分
public void RunAnimation(View v)
{
//The onClick method has to be present and must take the above parameter.
StartLoading();
//This will delay the stop for 5 seconds
//Normally you would want to actually have this run based on some other input/data.
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
StopLoading();
}
}, 5000);
}
public void StartLoading() {
ImageView refreshImage = (ImageView) this.findViewById(R.id.anim_example);
refreshImage.setImageDrawable(getResources().getDrawable(R.drawable.loading_circle));
Animation rotateLoading = AnimationUtils.loadAnimation(this, R.anim.rotate);
refreshImage.clearAnimation();
refreshImage.setAnimation(rotateLoading);
}
public void StopLoading() {
ImageView refreshImage = (ImageView) this.findViewById(R.id.anim_example);
if (refreshImage.getAnimation() != null)
{
refreshImage.clearAnimation();
refreshImage.setImageDrawable(getResources().getDrawable(R.drawable.loading_circle));
}
}
动画旋转:
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="359"
android:duration="2000"
android:repeatMode="restart"
android:repeatCount="-1"
android:pivotX="50%"
android:pivotY="50%">
标签:android
来源: https://codeday.me/bug/20191208/2088764.html