欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Android實(shí)現(xiàn)加載對(duì)話框的方法

這篇文章將為大家詳細(xì)講解有關(guān)Android實(shí)現(xiàn)加載對(duì)話框的方法,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、小程序定制開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了秀嶼免費(fèi)建站歡迎大家使用!

具體內(nèi)容如下

這里簡(jiǎn)單說(shuō)一下兩種實(shí)現(xiàn)加載對(duì)話框的方式:1.使用動(dòng)畫讓一個(gè)圖片旋轉(zhuǎn) 2.使用progressbar。

感覺(jué)簡(jiǎn)單來(lái)說(shuō),dialog就是一個(gè)彈出的window,把自己定義的布局放置到window里面就可以了,加載對(duì)話框就是有個(gè)加載的動(dòng)畫,核心的地方就是實(shí)現(xiàn)這個(gè)動(dòng)畫,所所以方法  可以有,對(duì)圖片添加動(dòng)畫,或者使用progressbar。

第一種方式:使用動(dòng)畫讓一個(gè)圖片旋轉(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,并對(duì)圖片添加旋轉(zhuǎn)動(dòng)畫:

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() {//對(duì)圖片添加旋轉(zhuǎn)動(dòng)畫
 // 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的動(dòng)畫:

<?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

首先是一個(gè)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>

看一下布局的實(shí)現(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
  
  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>

然后自定義一個(gè)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è)置對(duì)話框窗體大小
 getWindow().setContentView(mLayout);
 
 }
 
 
}

關(guān)于“Android實(shí)現(xiàn)加載對(duì)話框的方法”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

文章標(biāo)題:Android實(shí)現(xiàn)加載對(duì)話框的方法
轉(zhuǎn)載源于:http://chinadenli.net/article28/gophcp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、云服務(wù)器、品牌網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站網(wǎng)站策劃、軟件開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化