欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實現(xiàn)加載對話框

 更新時間:2020年01月30日 12:02:28   作者:楠之楓雪  
這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)加載對話框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android實現(xiàn)加載對話框的具體代碼,供大家參考,具體內(nèi)容如下

這里簡單說一下兩種實現(xiàn)加載對話框的方式:1.使用動畫讓一個圖片旋轉(zhuǎn) 2.使用progressbar。

感覺簡單來說,dialog就是一個彈出的window,把自己定義的布局放置到window里面就可以了,加載對話框就是有個加載的動畫,核心的地方就是實現(xiàn)這個動畫,所所以方法  可以有,對圖片添加動畫,或者使用progressbar。

第一種方式:使用動畫讓一個圖片旋轉(zhuǎn)

先看一下布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@drawable/dialog_bg_while"
 android:orientation="vertical" >
 
 <ImageView
  android:layout_width="54dp"
  android:id="@+id/loading_dialog_pic"
  android:layout_height="54dp"
  android:layout_gravity="center_horizontal"
  android:layout_marginTop="15dp"
  android:background="@drawable/loading" />
 
 <TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:layout_marginTop="10dp"
  android:text="正在加載..." />
 
</LinearLayout>

然后自定義Alertdialog,并對圖片添加旋轉(zhuǎn)動畫:

public class LoadingDialog extends AlertDialog {
 private final String DEFAULT_TEXT="正在加載";
 private ImageView mImageview;
 private TextView mTextView;
 private LinearLayout mLayout;
 private String mText;
 
 protected LoadingDialog(Context context) {
 super(context);
 // TODO Auto-generated constructor stub
 }
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 // TODO Auto-generated method stub
 super.onCreate(savedInstanceState);
 mLayout=(LinearLayout) LinearLayout.inflate(getContext(), R.layout.loading_dialog, null);
 mImageview=(ImageView) mLayout.findViewById(R.id.loading_dialog_pic);
 mTextView=(TextView) mLayout.findViewById(R.id.loading_dialog_text); 
 loadanimation();
 getWindow().setContentView(mLayout);
 
 }
 
 private void loadanimation() {//對圖片添加旋轉(zhuǎn)動畫
 // TODO Auto-generated method stub
 Animation anim=AnimationUtils.loadAnimation(getContext(), R.anim.loading_dialog_anim);
 LinearInterpolator lin = new LinearInterpolator(); 
 anim.setInterpolator(lin);
 mImageview.setAnimation(anim);
 
 }
 
 
}

看一下xml的動畫:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
 
 <rotate
  android:duration="1500"
  android:pivotX="50%"   
  android:pivotY="50%"
  android:fromDegrees="0.0" 
  android:repeatCount="infinite"
  android:toDegrees="-358" />
 
</set>

第二種方式:使用progressbar

首先是一個animation-list:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
 
 <item
  android:drawable="@drawable/loading1"
  android:duration="100"/>
 <item
  android:drawable="@drawable/loading2"
  android:duration="100"/>
 <item
  android:drawable="@drawable/loading3"
  android:duration="100"/>
 <item
  android:drawable="@drawable/loading4"
  android:duration="100"/>
 <item
  android:drawable="@drawable/loading5"
  android:duration="100"/>
 <item
  android:drawable="@drawable/loading6"
  android:duration="100"/>
 <item
  android:drawable="@drawable/loading7"
  android:duration="100"/>
 <item
  android:drawable="@drawable/loading8"
  android:duration="100"/>
 
 
</animation-list>

看一下布局的實現(xiàn):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="@drawable/dialog_bg_while"
 android:orientation="vertical" >
 
 <ProgressBar
  style="@android:style/Widget.ProgressBar.Large"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:layout_marginTop="10dp"
  android:indeterminateDrawable="@drawable/loading_animation_list"
  android:indeterminateDuration="1500" />
 
 <View
  android:layout_width="match_parent"
  android:layout_height="1dp"
  android:background="#00BCD4" />
 
 <TextView
  android:id="@+id/loading_dialog_text"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:layout_marginTop="10dp"
  android:text="正在加載..." />
 
</LinearLayout>

然后自定義一個alertdialog:

public class LoadingDialog extends AlertDialog {
 private final String DEFAULT_TEXT="正在加載";
 private TextView mTextView;
 private LinearLayout mLayout;
 private String mText;
 
 protected LoadingDialog(Context context) {
 super(context);
 // TODO Auto-generated constructor stub
 }
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 // TODO Auto-generated method stub
 super.onCreate(savedInstanceState);
 mLayout=(LinearLayout) LinearLayout.inflate(getContext(), R.layout.loading_dialog, null); 
 mTextView=(TextView) mLayout.findViewById(R.id.loading_dialog_text);
 WindowManager m=(WindowManager) getContext().getSystemService(getContext().WINDOW_SERVICE);
 int windowwith=m.getDefaultDisplay().getWidth();
 int w=windowwith*3/5;
 int h=300; 
 getWindow().setLayout(w, h);//設(shè)置對話框窗體大小
 getWindow().setContentView(mLayout);
 
 }
 
 
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 理解Android的手勢識別提高APP的用戶體驗

    理解Android的手勢識別提高APP的用戶體驗

    對于觸摸屏,其原生的消息無非按下、抬起、移動這幾種,我們只需要簡單重載onTouch或者設(shè)置觸摸偵聽器setOnTouchListener即可進(jìn)行處理
    2013-06-06
  • 在AndroidManifest.xml中uses-sdk內(nèi)屬性意思

    在AndroidManifest.xml中uses-sdk內(nèi)屬性意思

    本文為大家講解下minSdkVersion、targetSdkVersion、maxSdkVersion、target API level四個數(shù)值的意思與區(qū)別,感興趣的朋友可以參考下哈
    2013-06-06
  • Android自定義控件屬性詳細(xì)介紹

    Android自定義控件屬性詳細(xì)介紹

    這篇文章主要介紹了Android自定義控件屬性詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • Android ANR原理分析

    Android ANR原理分析

    ANR即Application Not Responding,顧名思義就是應(yīng)用程序無響應(yīng)。在Android中,一般情況下,四大組件均是工作在主線程中的,Android會隨時監(jiān)控應(yīng)用程序的響應(yīng)情況,如果因為一些耗時操作,那么系統(tǒng)就會顯示ANR對話框提示用戶對應(yīng)的應(yīng)用處于無響應(yīng)狀態(tài)
    2021-06-06
  • Flutter組件生命周期和App生命周期示例解析

    Flutter組件生命周期和App生命周期示例解析

    這篇文章主要為大家介紹了Flutter組件生命周期和App生命周期示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • Android實現(xiàn)webview實例代碼

    Android實現(xiàn)webview實例代碼

    本篇文章主要介紹了Android實現(xiàn)webview實例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • Android開發(fā)工程中集成mob短信驗證碼功能的方法

    Android開發(fā)工程中集成mob短信驗證碼功能的方法

    這篇文章主要介紹了Android開發(fā)工程中集成mob短信驗證碼功能的方法,感興趣的小伙伴們可以參考一下
    2016-05-05
  • FragmentTabHost FrameLayout實現(xiàn)底部導(dǎo)航欄

    FragmentTabHost FrameLayout實現(xiàn)底部導(dǎo)航欄

    這篇文章主要為大家詳細(xì)介紹了FragmentTabHost和FrameLayout實現(xiàn)底部導(dǎo)航欄,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Android安裝apk文件并適配Android 7.0詳解

    Android安裝apk文件并適配Android 7.0詳解

    這篇文章主要介紹了Android安裝apk文件并適配Android 7.0詳解的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • Flutter深色模式適配的實現(xiàn)

    Flutter深色模式適配的實現(xiàn)

    這篇文章主要介紹了Flutter深色模式適配的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04

最新評論