Dialog加载页面动画(Loding.....加载等待)三种方式

方式一:帧动画切换效果(几张图片切换)

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>


2.mydialog.xml(普通布局)


<?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>


3.MyDialog类:


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提示框


4.需要dialog的Activity写下方法,调用即可


 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;
    
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值