1.第一步实现动画的内容的xml文件:页面很简单。
```java
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="?attr/colorControlHighlight"
android:orientation="horizontal">
<ImageView
android:id="@+id/imagelong"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@mipmap/shezhi" />
<TextView
android:id="@+id/tvlong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="正在加载中" />
</LinearLayout>
2.用写对应的java代码
```java
```java
public class Loading extends Dialog {
private ImageView imageView;
private Button button;
private Handler handler;
private Runnable runnable;
/**
*
*/
public Loading(@NonNull Context context) {
super(context);
setContentView(R.layout.londing);
/*
设置旋转动画
*/
Animation circle_anim = AnimationUtils.loadAnimation(context, R.anim.anim_round_rotate);
LinearInterpolator interpolator = new LinearInterpolator(); //设置匀速旋转,在xml文件中设置会出现卡顿
circle_anim.setInterpolator(interpolator);
imageView=findViewById(R.id.imagelong);
imageView.startAnimation(circle_anim);
//这里Handler的postDelayed方法,等待10000毫秒在执行run方法。
//在Activity中我们经常需要使用Handler方法更新UI或者执行一些耗时事件,
//并且Handler中post方法既可以执行耗时事件也可以做一些UI更新的事情,比较好用,推荐使用
handler=new Handler();
runnable=new Runnable(){
public void run(){
//等待10000毫秒后销毁此页面,并提示
Loading.this.hide();
Toast.makeText(getContext(), "哈哈哈", Toast.LENGTH_LONG).show();
}
};
handler.postDelayed(runnable,10000);
}
}
3.写照片旋转的对应xml文件/res/anim/anim_round_rotate.xml
```java
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="359"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:repeatCount="-1" />
<!--设置不断旋转-->
<!--toDegrees0~359防止卡顿-->
<!--pivotX设置旋转中心点为控件中心-->
</set>
4.在想用的 地方调用
```java
new Loading(this).show();