最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 開發(fā)使用PopupWindow實(shí)現(xiàn)加載等待界面功能示例

 更新時(shí)間:2020年05月21日 10:51:05   作者:LIFE_R  
這篇文章主要介紹了Android 開發(fā)使用PopupWindow實(shí)現(xiàn)加載等待界面功能,結(jié)合實(shí)例形式分析了Android使用PopupWindow組件實(shí)現(xiàn)加載等待界面功能相關(guān)布局與功能實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android 開發(fā)使用PopupWindow實(shí)現(xiàn)加載等待界面功能。分享給大家供大家參考,具體如下:

實(shí)現(xiàn)加載等待界面我用了兩種方式,一種是用PopupWindow實(shí)現(xiàn),另一種便是用Activity實(shí)現(xiàn)。用Activity實(shí)現(xiàn)方法請(qǐng)見我的另一篇博客:

Android 使用Activity實(shí)現(xiàn)加載等待界面

首先看效果:

用PopupWindow實(shí)現(xiàn)此功能還是比較簡(jiǎn)單的,首先我們寫一個(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)聽事件:

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"
  style="?android:attr/progressBarStyle"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerInParent="true"/>

</RelativeLayout>

大功告成,運(yùn)行一下即可??!

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫(kù)操作技巧總結(jié)》及《Android資源操作技巧匯總

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

广宁县| 甘肃省| 涪陵区| 宁都县| 西盟| 岑巩县| 南皮县| 屏南县| 页游| 即墨市| 垦利县| 双城市| 新化县| 阿克苏市| 南江县| 聂拉木县| 新密市| 赫章县| 江北区| 尚志市| 克拉玛依市| 九江市| 新竹市| 斗六市| 许昌市| 浦城县| 桦甸市| 名山县| 乌拉特后旗| 比如县| 莒南县| 睢宁县| 类乌齐县| 昭苏县| 桃园县| 宁都县| 宁陕县| 象州县| 志丹县| 宣恩县| 中卫市|