Android之仿美團加載數(shù)據(jù)幀動畫
一:先來張效果圖(這里是GIF動畫,我就截屏的所有沒有動畫,實際是動的):

二:實現(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="點擊彈出動畫"
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 奔跑小人的動畫彈框,可以用作加載數(shù)據(jù)界面
* 2017-4-3 http://blog.csdn.net/android_cll
*/
public class RuningManActivity extends Activity implements View.OnClickListener {
private TextView textview;//點擊按鈕
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac_runing_man);
initlayout();
}
/**
* 實例化
*/
private void initlayout() {
textview = (TextView) findViewById(R.id.textview);
textview.setOnClickListener(this);
}
/**
* 顯示美團進度對話框
*
* @param v
*/
public void showmeidialog(View v) {
CustomProgressDialog dialog = new CustomProgressDialog(this, "正在加載中......", R.anim.animation);
dialog.setCanceledOnTouchOutside(false);//設(shè)置是否可以點擊外部消失
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對象拿到背景顯示的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文件下的幀動畫文件
<?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ù)彈框的幀動畫功能就實現(xiàn)了,不喜勿噴,都有注釋就不用解釋太多
最后附上源碼:http://download.csdn.net/download/android_cll/9802503
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
Android字符串和十六進制相互轉(zhuǎn)化出現(xiàn)的中文亂碼問題
這篇文章主要介紹了Android字符串和十六進制相互轉(zhuǎn)化出現(xiàn)的中文亂碼問題的相關(guān)資料,需要的朋友可以參考下2016-02-02
基于android樣式與主題(style&theme)的詳解
本篇文章是對android中的樣式與主題(style&theme)進行了詳細的分析介紹,需要的朋友參考下2013-06-06
Android 6.0動態(tài)權(quán)限及跳轉(zhuǎn)GPS設(shè)置界面的方法
今天小編就為大家分享一篇Android 6.0動態(tài)權(quán)限及跳轉(zhuǎn)GPS設(shè)置界面的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07
Android 判斷SIM卡屬于哪個移動運營商的實現(xiàn)代碼
有時候我們需要在Android中獲取本機網(wǎng)絡(luò)提供商呢,這里簡單分享下,方便需要的朋友2013-05-05
Android 使用fast-verification實現(xiàn)驗證碼填寫功能的實例代碼
這篇文章主要介紹了Android 使用fast-verification實現(xiàn)驗證碼填寫功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04
Android AlertDialog自定義樣式實現(xiàn)代碼
這篇文章主要介紹了Android AlertDialog自定義樣式實現(xiàn)代碼的相關(guān)資料,這里提供了實例代碼,一個簡單示例,需要的朋友可以參考下2016-12-12

