方式一:利用ProgressBar自带属性
<ProgressBar
android:id="@+id/iv_progress"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginStart="90dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="90dp"
android:indeterminateDrawable="@drawable/loading_bg"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
loading_bg
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:drawable="@mipmap/loading"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="720" />
</item>
</layer-list>
方式二:利用旋转动画
ImageView mOtherDeviceScanImg = mBinding.ivOtherDeviceListRefresh;
Animation mRotateAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.loading_animator);
if (mOtherDeviceScanImg == null) {
LogUtils.d(TAG, "setRotateAnimation mOtherDeviceScanImg: " + mOtherDeviceScanImg);
return;
}
if (start) {
mOtherDeviceScanImg.startAnimation(mRotateAnimation);
} else {
mRotateAnimation.cancel();
mOtherDeviceScanImg.clearAnimation();
}
loading_animator
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="2000"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="359" />
</set>
0 条评论