Android模擬美團(tuán)客戶端進(jìn)度提示框
用過美團(tuán)客戶端的朋友都知道,美團(tuán)的加載等待提示很有意思,是一種動(dòng)畫的形式展現(xiàn)給我們,下面我們就對(duì)這背后的原理進(jìn)行了解,然后實(shí)現(xiàn)自己的等待動(dòng)畫效果。
首先我們準(zhǔn)備兩張圖片:
這兩張圖片看起來一模一樣啊?細(xì)心的朋友會(huì)發(fā)現(xiàn)唯一不同的就在腳部,OK,我們就利用這兩張圖片的輪換播放實(shí)現(xiàn)動(dòng)畫效果,下面看一下代碼:
1.動(dòng)畫文件frame_meituan.xml:
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://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>
150毫秒進(jìn)行圖片的切換,模擬動(dòng)畫效果。
2.簡(jiǎn)單自定義一個(gè)控件-MeituanProgressDialog.java:
package com.finddreams.runningman; import android.app.ProgressDialog; import android.content.Context; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.widget.ImageView; import android.widget.TextView; import com.example.runningman.R; /** * @Description:自定義對(duì)話框 * @author http://blog.csdn.net/yayun0516 */ public class MeituanProgressDialog extends ProgressDialog { private AnimationDrawable mAnimation; private Context mContext; private ImageView mImageView; private String mLoadingTip; private TextView mLoadingTv; private int count = 0; private String oldLoadingTip; private int mResid; /** * * @param context * 上下文對(duì)象 * @param content * 顯示文字提示信息內(nèi)容 * @param id * 動(dòng)畫id */ public MeituanProgressDialog(Context context, String content, int id) { super(context); this.mContext = context; this.mLoadingTip = content; this.mResid = id; setCanceledOnTouchOutside(true); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initView(); initData(); } private void initData() { mImageView.setBackgroundResource(mResid); // 通過ImageView對(duì)象拿到背景顯示的AnimationDrawable mAnimation = (AnimationDrawable) mImageView.getBackground(); mImageView.post(new Runnable() { @Override public void run() { mAnimation.start(); } }); mLoadingTv.setText(mLoadingTip); } public void setContent(String str) { mLoadingTv.setText(str); } private void initView() { setContentView(R.layout.progress_dialog);// 顯示界面 mLoadingTv = (TextView) findViewById(R.id.loadingTv); mImageView = (ImageView) findViewById(R.id.loadingIv); } }
上面用到的提示布局文件的progress_dialog.xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="vertical" > <ImageView android:id="@+id/loadingIv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@anim/frame_meituan"/> <TextView android:id="@+id/loadingTv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/loadingIv" android:layout_centerHorizontal="true" android:textSize="20sp" android:text="正在加載中.." /> </RelativeLayout>
最后在Activity中調(diào)用:
package com.finddreams.runningman; import com.example.runningman.R; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.view.View; /** * @Description: 奔跑小人的動(dòng)畫進(jìn)度條對(duì)話框,可以用作加載數(shù)據(jù)界面 * @author http://blog.csdn.net/yayun0516 */ public class MeiTuanManActivity extends Activity { private MeituanProgressDialog dialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.meituan_progressdialog); } /** * 顯示美團(tuán)進(jìn)度對(duì)話框 * @param v */ public void showmeidialog(View v){ dialog =new MeituanProgressDialog(this, "正在加載中",R.anim.frame_meituan); dialog.show(); Handler handler =new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { dialog.dismiss(); } }, 3000);//3秒鐘后調(diào)用dismiss方法隱藏; } }
最后,讓我們的程序跑起來:
ok,跑起來了,你想要加入你的項(xiàng)目,只需要準(zhǔn)備兩張圖片替換下來即可模擬動(dòng)畫。
- android 彈出提示框的使用(圖文實(shí)例)
- Android使用Toast顯示消息提示框
- android實(shí)現(xiàn)彈出提示框
- Android仿QQ、微信聊天界面長(zhǎng)按提示框效果
- Android編程之自定義AlertDialog(退出提示框)用法實(shí)例
- Android仿IOS自定義AlertDialog提示框
- Android仿百度谷歌搜索自動(dòng)提示框AutoCompleteTextView簡(jiǎn)單應(yīng)用示例
- Android超實(shí)用的Toast提示框優(yōu)化分享
- Android中仿IOS提示框的實(shí)現(xiàn)方法
- Android模仿Toast實(shí)現(xiàn)提示框效果
相關(guān)文章
Android Back鍵點(diǎn)擊兩次退出應(yīng)用詳解及實(shí)現(xiàn)方法總結(jié)
這篇文章主要介紹了Android Back鍵點(diǎn)擊兩次退出應(yīng)用詳解及實(shí)現(xiàn)方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2016-10-10Android中制作進(jìn)度框和環(huán)形進(jìn)度條的簡(jiǎn)單實(shí)例分享
這篇文章主要介紹了Android中制作進(jìn)度框和環(huán)形進(jìn)度條的簡(jiǎn)單實(shí)例分享,環(huán)形進(jìn)度條帶有基本的百分比顯示,需要的朋友可以參考下2016-03-03Android中實(shí)現(xiàn)開機(jī)自動(dòng)啟動(dòng)服務(wù)(service)實(shí)例
這篇文章主要介紹了Android中實(shí)現(xiàn)自動(dòng)啟動(dòng)服務(wù)實(shí)例,并開機(jī)自動(dòng)啟用(無activity),的朋友可以參考下2014-06-06Flutter仿微信通訊錄實(shí)現(xiàn)自定義導(dǎo)航條的示例代碼
某些頁(yè)面比如我們?cè)谶x擇聯(lián)系人或者某個(gè)城市的時(shí)候需要快速定位到我們需要的選項(xiàng),一般都會(huì)需要像微信通訊錄右邊有一個(gè)導(dǎo)航條一樣的功能,本文將利用Flutter實(shí)現(xiàn)這一效果,需要的可以參考一下2022-04-04TextView中URL等指定特殊字符串與點(diǎn)擊事件解析
這篇文章主要為大家詳細(xì)介紹了TextView中URL等指定特殊字符串與點(diǎn)擊事件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11Android編程單擊圖片實(shí)現(xiàn)切換效果的方法
這篇文章主要介紹了Android編程單擊圖片實(shí)現(xiàn)切換效果的方法,以實(shí)例形式分析了Android布局及切換功能的具體實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10android Textview文字監(jiān)控(Textview使用方法)
以手機(jī)號(hào)充值為例,當(dāng)用戶輸入最后一位數(shù)時(shí)候,進(jìn)行匯率的變換,本文就實(shí)現(xiàn)類似這樣的功能2013-11-11Android UI實(shí)現(xiàn)多行文本折疊展開效果
這篇文章主要為大家詳細(xì)介紹了Android UI實(shí)現(xiàn)多行文本折疊展開效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10Android?獲取手機(jī)已安裝的應(yīng)用列表實(shí)現(xiàn)詳解
這篇文章主要介紹了Android?獲取手機(jī)已安裝的應(yīng)用列表的實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08