Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 模擬美團風格進度提示框

編輯:關於 Android 程式設計

實作概念

美團風格的等待提示框通常以動畫呈現。這裡可透過兩張圖片輪流切換,模擬人物奔跑或等待中的動畫效果。

建立動畫資源

<animation-list xmlns:android="https://schemas.android.com/apk/res/android" android:oneshot="false">
    <item android:drawable="@drawable/progress_loading_image_01" android:duration="150"/>
    <item android:drawable="@drawable/progress_loading_image_02" android:duration="150"/>
</animation-list>

自訂 ProgressDialog

public class MeituanProgressDialog extends ProgressDialog {
    private AnimationDrawable mAnimation;
    private ImageView mImageView;
    private TextView mLoadingTv;

    public MeituanProgressDialog(Context context, String content, int id) {
        super(context);
        this.mLoadingTip = content;
        this.mResid = id;
        setCanceledOnTouchOutside(true);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.progress_dialog);
        mLoadingTv = (TextView) findViewById(R.id.loadingTv);
        mImageView = (ImageView) findViewById(R.id.loadingIv);
        mImageView.setBackgroundResource(mResid);
        mAnimation = (AnimationDrawable) mImageView.getBackground();
        mImageView.post(new Runnable() {
            @Override
            public void run() {
                mAnimation.start();
            }
        });
        mLoadingTv.setText(mLoadingTip);
    }
}

呼叫方式

MeituanProgressDialog dialog = new MeituanProgressDialog(this, "正在加載中", R.anim.frame_meituan);
dialog.show();
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved