Android之仿美團(tuán)加載數(shù)據(jù)幀動(dòng)畫
一:先來張效果圖(這里是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);
// 通過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
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(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編程之簡單逐幀動(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字符串和十六進(jìn)制相互轉(zhuǎn)化出現(xiàn)的中文亂碼問題
這篇文章主要介紹了Android字符串和十六進(jìn)制相互轉(zhuǎn)化出現(xiàn)的中文亂碼問題的相關(guān)資料,需要的朋友可以參考下2016-02-02
基于android樣式與主題(style&theme)的詳解
本篇文章是對(duì)android中的樣式與主題(style&theme)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
Android 6.0動(dòng)態(tài)權(quán)限及跳轉(zhuǎn)GPS設(shè)置界面的方法
今天小編就為大家分享一篇Android 6.0動(dòng)態(tài)權(quán)限及跳轉(zhuǎn)GPS設(shè)置界面的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-07-07
Android中實(shí)現(xiàn)GPS定位的簡單例子
這篇文章主要介紹了Android中實(shí)現(xiàn)GPS定位的簡單例子,例子邏輯清晰,但相對(duì)簡單了些,需要的朋友可以參考下2014-07-07
Android 判斷SIM卡屬于哪個(gè)移動(dòng)運(yùn)營商的實(shí)現(xiàn)代碼
有時(shí)候我們需要在Android中獲取本機(jī)網(wǎng)絡(luò)提供商呢,這里簡單分享下,方便需要的朋友2013-05-05
Android 使用fast-verification實(shí)現(xiàn)驗(yàn)證碼填寫功能的實(shí)例代碼
這篇文章主要介紹了Android 使用fast-verification實(shí)現(xiàn)驗(yàn)證碼填寫功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
Android AlertDialog自定義樣式實(shí)現(xiàn)代碼
這篇文章主要介紹了Android AlertDialog自定義樣式實(shí)現(xiàn)代碼的相關(guān)資料,這里提供了實(shí)例代碼,一個(gè)簡單示例,需要的朋友可以參考下2016-12-12

