這篇文章主要為大家展示了Android開(kāi)發(fā)如何使用PopupWindow實(shí)現(xiàn)加載等待界面,內(nèi)容簡(jiǎn)而易懂,希望大家可以學(xué)習(xí)一下,學(xué)習(xí)完之后肯定會(huì)有收獲的,下面讓小編帶大家一起來(lái)看看吧。
目前創(chuàng)新互聯(lián)公司已為上千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、資溪網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
實(shí)現(xiàn)加載等待界面我用了兩種方式,一種是用PopupWindow實(shí)現(xiàn),另一種便是用Activity實(shí)現(xiàn)。用Activity實(shí)現(xiàn)方法請(qǐng)見(jiàn)我的另一篇博客:
Android 使用Activity實(shí)現(xiàn)加載等待界面
首先看效果:

用PopupWindow實(shí)現(xiàn)此功能還是比較簡(jiǎn)單的,首先我們寫(xiě)一個(gè)布局,只有一個(gè)登錄按鈕,用于觸發(fā)等待界面:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context="com.toprs.myapplication.MainActivity"> <Button android:text="登錄" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="loginClick" android:id="@+id/button2"/> </LinearLayout>
然后為登錄按鈕添加監(jiān)聽(tīng)事件:
package com.wang.myapplication;
import ...
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void loginClick(View v){
final PopupWindow popupWindow = new PopupWindow();
popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(true);
View view = LayoutInflater.from(this).inflate(R.layout.popup,null);
popupWindow.setContentView(view);
popupWindow.showAtLocation(getWindow().getDecorView(), Gravity.CENTER,0,0);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "登錄成功", Toast.LENGTH_SHORT).show();
popupWindow.dismiss();
}
},2000);
}
}其中彈出的PopupWindow需要一個(gè)布局,也就是簡(jiǎn)單放入一個(gè)ProgressBar:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="200dp">
<ProgressBar
android:id="@+id/progressBar4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>大功告成,運(yùn)行一下即可!!
以上就是關(guān)于Android開(kāi)發(fā)如何使用PopupWindow實(shí)現(xiàn)加載等待界面的內(nèi)容,如果你們有學(xué)習(xí)到知識(shí)或者技能,可以把它分享出去讓更多的人看到。
標(biāo)題名稱:Android開(kāi)發(fā)如何使用PopupWindow實(shí)現(xiàn)加載等待界面
標(biāo)題URL:http://chinadenli.net/article40/jiejho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、定制網(wǎng)站、微信公眾號(hào)、網(wǎng)站設(shè)計(jì)公司、靜態(tài)網(wǎng)站、電子商務(wù)
聲明:本網(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)