Android中怎么實現(xiàn)加載對話框效果

Android中怎么實現(xiàn)加載對話框效果,針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

成都創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),龍鳳企業(yè)網(wǎng)站建設(shè),龍鳳品牌網(wǎng)站建設(shè),網(wǎng)站定制,龍鳳網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,龍鳳網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。

第一種方式:使用動畫讓一個圖片旋轉(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    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); }}

關(guān)于Android中怎么實現(xiàn)加載對話框效果問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。

網(wǎng)站名稱:Android中怎么實現(xiàn)加載對話框效果
當(dāng)前鏈接:http://muchs.cn/article32/pipipc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化自適應(yīng)網(wǎng)站、網(wǎng)站排名靜態(tài)網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)軟件開發(fā)

廣告

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

營銷型網(wǎng)站建設(shè)