方式一:帧动画切换效果(几张图片切换)
1.drawable 下创建资源(多张图片~根据自己需要)
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/a"
android:duration="150"/>
<item
android:drawable="@drawable/b"
android:duration="150"/>
<item
android:drawable="@drawable/c"
android:duration="150"/>
</animation-list>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/loadingIv"
android:layout_width="30dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:background="@drawable/s"/>
<TextView
android:id="@+id/loadingTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/loadingIv"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="加载中...."
android:textColor="#fff"
android:textSize="15dp"/>
</RelativeLayout>
public class MyDialog extends ProgressDialog{
private AnimationDrawable mAnimation;
private ImageView mImageView;
private TextView mTextView;
private String loadingTip;
private int resid;
/**
*
* @param context 上下文对象
* @param content 显示文字提示信息内容
* @param id 动画id
*/
public MyDialog(Context context, String content, int resid) {
super(context);
this.loadingTip = content;
this.resid = resid;
//点击提示框外面是否取消提示框
setCanceledOnTouchOutside(false);
//点击返回键是否取消提示框
setCancelable(false);
setIndeterminate(true);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog);
mTextView = (TextView) findViewById(R.id.loadingTv);
mImageView = (ImageView) findViewById(R.id.loadingIv);
mImageView.setBackgroundResource(resid);
// 通过ImageView对象拿到背景显示的AnimationDrawable
mAnimation = (AnimationDrawable) mImageView.getBackground();
mImageView.post(new Runnable() {
@Override
public void run() {
mAnimation.start();
}
});
mTextView.setText(loadingTip);
}
}
//最后在activity中进行调用,这样就完成了一个自定义的dialog提示框
public void showMyDialog() {
dialog = new MyDialog(this, "正在加载中", R.drawable.s);
dialog.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
dialog.dismiss();
}
}, 5000);
}
方式二:圆形彩球旋转效果
1.建类 EaseInOutCubicInterpolator(复制)
public class EaseInOutCubicInterpolator implements TimeInterpolator{
@Override
public float getInterpolation(float input) {
if ((input *= 2) < 1.0f) {
return 0.5f * input * input * input;
}
input -= 2;
return 0.5f * input * input * input + 1;