android實(shí)現(xiàn)加載動(dòng)畫對話框
本文實(shí)例為大家分享了android實(shí)現(xiàn)加載動(dòng)畫對話框的具體代碼,供大家參考,具體內(nèi)容如下
先來兩張效果圖
自定義對話框:
public class LoadingProgressDialog extends ProgressDialog { private AnimationDrawable mAnimation; private Context mContext; private ImageView mImageView; private String mLoadingTitle; private TextView mLoadingTv; private int mResid; public LoadingProgressDialog(Context context, String content, int id) { super(context); this.mContext = context; this.mLoadingTitle = content; this.mResid = id; setCanceledOnTouchOutside(true); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initView(); initData(); } private void initData() { mImageView.setBackgroundResource(mResid); mAnimation = (AnimationDrawable) mImageView.getBackground(); mImageView.post(new Runnable() { @Override public void run() { mAnimation.start(); } }); mLoadingTv.setText(mLoadingTitle); } 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); } }
在layout文件夾下建立progress_dialog.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:layout_gravity="center" android:orientation="vertical"> <ImageView android:id="@+id/loadingIv" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/loadingTv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:textSize="20sp" /> </LinearLayout>
在res文件夾下建立anim文件夾,然后在里面建立frame.xml
動(dòng)畫是由一張一張的圖片逐幀播放的,里面每一個(gè)item就是一張圖片,動(dòng)畫有多少幀就有多少張圖片,有多少圖片就有多少item。
<?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/loading_01" android:duration="100" /> <item android:drawable="@drawable/loading_02" android:duration="100" /> <item android:drawable="@drawable/loading_03" android:duration="100" /> <item android:drawable="@drawable/loading_04" android:duration="100" /> </animation-list>
用法:
LoadingProgressDialog dialog =new LoadingProgressDialog(MainActivity.this, "正在加載中...",R.anim.frame); //打開 dialog.show(); //隱藏 dialog.dismiss();
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
android獲取音樂文件的內(nèi)置專輯圖片實(shí)現(xiàn)思路及代碼
獲取音樂文件的內(nèi)置專輯圖片這是在播放音樂時(shí)的一個(gè)很不錯(cuò)的功能,下面與大家分享下具體的實(shí)現(xiàn)思路,有類似需求的朋友可以參考下哈2013-06-06Material Design系列之Behavior實(shí)現(xiàn)Android知乎首頁
這篇文章主要為大家詳細(xì)介紹了Material Design系列之Behavior實(shí)現(xiàn)Android知乎首頁的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09Android仿知乎客戶端關(guān)注和取消關(guān)注的按鈕點(diǎn)擊特效實(shí)現(xiàn)思路詳解
這篇文章主要介紹了Android仿知乎客戶端關(guān)注和取消關(guān)注的按鈕點(diǎn)擊特效實(shí)現(xiàn)思路詳解的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09Arduino 數(shù)據(jù)類型轉(zhuǎn)換(單機(jī)片)詳細(xì)介紹
這篇文章主要介紹了Arduino 數(shù)據(jù)類型轉(zhuǎn)換(單機(jī)片)詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2016-11-11Android 數(shù)據(jù)庫打包隨APK發(fā)布的實(shí)例代碼
有些時(shí)候我們的軟件用到SQLite數(shù)據(jù)庫,這個(gè)時(shí)候怎么把一個(gè)做好的數(shù)據(jù)庫打包進(jìn)我們的APK呢2013-10-10Android WebView上實(shí)現(xiàn)JavaScript與Java交互
這篇文章主要介紹了Android WebView上實(shí)現(xiàn)JavaScript與Java交互 的相關(guān)資料,需要的朋友可以參考下2016-03-03安卓監(jiān)聽屏幕的橫豎翻轉(zhuǎn)實(shí)現(xiàn)方法
這篇文章主要介紹了安卓監(jiān)聽屏幕的橫豎翻轉(zhuǎn)實(shí)現(xiàn)方法,有需要的朋友可以參考一下2013-12-12