Android之仿美團(tuán)加載數(shù)據(jù)幀動(dòng)畫
一:先來(lái)張效果圖(這里是GIF動(dòng)畫,我就截屏的所有沒有動(dòng)畫,實(shí)際是動(dòng)的):
二:實(shí)現(xiàn)步驟:
1、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"> <TextView android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="50dp" android:layout_alignParentBottom="true" android:layout_margin="20dp" android:background="@drawable/animationtk" android:gravity="center" android:text="點(diǎn)擊彈出動(dòng)畫" android:textColor="#fff" android:textSize="18dp" /> </RelativeLayout>
2.activity代碼
package cll.com.myapplication; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.TextView; /** * @Description 奔跑小人的動(dòng)畫彈框,可以用作加載數(shù)據(jù)界面 * 2017-4-3 http://blog.csdn.net/android_cll */ public class RuningManActivity extends Activity implements View.OnClickListener { private TextView textview;//點(diǎn)擊按鈕 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ac_runing_man); initlayout(); } /** * 實(shí)例化 */ private void initlayout() { textview = (TextView) findViewById(R.id.textview); textview.setOnClickListener(this); } /** * 顯示美團(tuán)進(jìn)度對(duì)話框 * * @param v */ public void showmeidialog(View v) { CustomProgressDialog dialog = new CustomProgressDialog(this, "正在加載中......", R.anim.animation); dialog.setCanceledOnTouchOutside(false);//設(shè)置是否可以點(diǎn)擊外部消失 dialog.setCancelable(false);//設(shè)置是否可以按退回鍵取消 dialog.show(); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.textview: showmeidialog(view); break; } } }
3.自定義彈框工具類
package cll.com.myapplication; 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; /** * @Description:自定義加載數(shù)據(jù)彈框 * @author 2017-4-3 http://blog.csdn.net/android_cll */ public class CustomProgressDialog extends ProgressDialog { private AnimationDrawable mAnimation; private ImageView mImageView; private String mLoadingTip; private TextView mLoadingTv; private int mResid; public CustomProgressDialog(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); initView(); initData(); } private void initData() { mImageView.setBackgroundResource(mResid); // 通過(guò)ImageView對(duì)象拿到背景顯示的AnimationDrawable mAnimation = (AnimationDrawable) mImageView.getBackground(); // 為了防止在onCreate方法中只顯示第一幀的解決方案之一 mImageView.post(new Runnable() { @Override public void run() { mAnimation.start(); } }); mLoadingTv.setText(mLoadingTip); } private void initView() { setContentView(R.layout.progress_dialog); mLoadingTv = (TextView) findViewById(R.id.loadingTv); mImageView = (ImageView) findViewById(R.id.loadingIv); } }
4.自定義彈框的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/animation"/> <TextView android:id="@+id/loadingTv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/loadingIv" android:textColor="#fff" android:layout_centerHorizontal="true" android:textSize="20sp" android:text="正在加載中.." /> </RelativeLayout>
5.anim文件下的幀動(dòng)畫文件
<?xml version="1.0" encoding="utf-8"?> <animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@mipmap/progress_loading_image" android:duration="150"/> <item android:drawable="@mipmap/progress_loading_imagey" android:duration="150"/> </animation-list>
到此加載數(shù)據(jù)彈框的幀動(dòng)畫功能就實(shí)現(xiàn)了,不喜勿噴,都有注釋就不用解釋太多
最后附上源碼:http://download.csdn.net/download/android_cll/9802503
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
- Android動(dòng)畫之逐幀動(dòng)畫(Frame Animation)實(shí)例詳解
- Android 動(dòng)畫(View動(dòng)畫,幀動(dòng)畫,屬性動(dòng)畫)詳細(xì)介紹
- Android逐幀動(dòng)畫實(shí)現(xiàn)代碼
- Android 使用幀動(dòng)畫內(nèi)存溢出解決方案
- Android動(dòng)畫之逐幀動(dòng)畫(Frame Animation)基礎(chǔ)學(xué)習(xí)
- Android幀動(dòng)畫、補(bǔ)間動(dòng)畫、屬性動(dòng)畫用法詳解
- Android編程之簡(jiǎn)單逐幀動(dòng)畫Frame的實(shí)現(xiàn)方法
- Android 幀動(dòng)畫的實(shí)例詳解
- Android 逐幀動(dòng)畫創(chuàng)建實(shí)例詳解
- Android Studio實(shí)現(xiàn)幀動(dòng)畫
相關(guān)文章
Android實(shí)現(xiàn)手勢(shì)滑動(dòng)識(shí)別功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)手勢(shì)滑動(dòng)識(shí)別功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06Android開發(fā)之Location用法實(shí)例分析
這篇文章主要介紹了Android開發(fā)中Location用法,結(jié)合實(shí)例形式分析了Android使用location控件獲取經(jīng)緯度信息的相關(guān)操作技巧,需要的朋友可以參考下2016-10-10flutter實(shí)現(xiàn)掃碼槍獲取數(shù)據(jù)源禁止系統(tǒng)鍵盤彈窗示例詳解
這篇文章主要為大家介紹了flutter實(shí)現(xiàn)掃碼槍獲取數(shù)據(jù)源禁止系統(tǒng)鍵盤彈窗示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01Android編程記錄ListView標(biāo)記行狀態(tài)的方法
這篇文章主要介紹了Android編程記錄ListView標(biāo)記行狀態(tài)的方法,結(jié)合實(shí)例分析了ListView標(biāo)記的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11Android CountDownTimer實(shí)現(xiàn)定時(shí)器和倒計(jì)時(shí)效果
這篇文章主要為大家詳細(xì)介紹了Android CountDownTimer實(shí)現(xiàn)定時(shí)器和倒計(jì)時(shí)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02Android的多媒體管理庫(kù)Glide的基本使用示例
這篇文章主要介紹了Android的多媒體管理庫(kù)Glide的基本使用示例,Glide在圖片App中的表現(xiàn)非常好,Google旗下的Yelp也在使用,需要的朋友可以參考下2016-04-04Android ListView與RecycleView的對(duì)比使用解析
這篇文章主要介紹了Android ListView與RecycleView的對(duì)比使用解析,需要的朋友可以參考下2017-12-12使用User Agent分辨出Android設(shè)備類型的安全做法
這篇文章主要介紹了使用User Agent分辨出Android設(shè)備類型的安全做法,本文得出的結(jié)論是當(dāng)你依據(jù)檢測(cè)UA來(lái)判斷Android手機(jī)設(shè)備,請(qǐng)同時(shí)檢查android和mobile兩個(gè)字符串,需要的朋友可以參考下2015-01-01Android自定義相機(jī)實(shí)現(xiàn)定時(shí)拍照功能
這篇文章主要為大家詳細(xì)介紹了Android自定義相機(jī)實(shí)現(xiàn)定時(shí)拍照功能的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01