加載頁面遮擋耗時操作任務(wù)頁面--第三方開源之AndroidProgressLayout

AndroidProgressLayout實現(xiàn)為界面添加圓形進度條。調(diào)用setprogress()方法顯示和隱藏進度條
在Android的開發(fā)中,往往有這種需求,比如一個耗時的操作,聯(lián)網(wǎng)獲取網(wǎng)絡(luò)圖片、內(nèi)容,數(shù)據(jù)庫耗時讀寫等等,在此耗時操作過程中,開發(fā)者也許不希望用戶再進行其他操作(其他操作可能會引起邏輯混亂),而此時需要給用戶一個額外的加載頁面遮擋住主邏輯代碼的運行,待主頁面的耗時操作完成后,自動消失這樣加載過度頁面,恢復(fù)出正常應(yīng)該顯示的頁面。
舉個實際的例子,如代碼使用Android WebView打開一個網(wǎng)頁鏈接試圖加載某個網(wǎng)站,但網(wǎng)絡(luò)質(zhì)量不佳,需要耗時很久,那么在這個過程中,較好的用戶體驗做法是:給用戶一個加載進度頁面,遮擋住WebView。當(dāng)加載的內(nèi)容成功后在完全切換回正常的邏輯頁面。
Android AndroidProgressLayout實現(xiàn)了這樣的功能,Android AndroidProgressLayout在github上的項目主頁是:https://github.com/antonkrasov/AndroidProgressLayout
測試代碼如下:
activity_main.xml:
<com.github.androidprogresslayout.ProgressLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:progressLayout="http://schemas.android.com/apk/res-auto" android:id="@+id/progressLayout" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="sp" android:layout_centerInParent="true" /> </com.github.androidprogresslayout.ProgressLayout>
MainActivity.java:
package com.zzw.testandroidprogresslayout;
import com.github.androidprogresslayout.ProgressLayout;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.animation.Animation;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ProgressLayout progressLayout = (ProgressLayout) findViewById(R.id.progressLayout);
final TextView textView = (TextView) findViewById(R.id.textView);
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
textView.setText("測試完成");
// 切換回正常顯示頁面
progressLayout.showContent();
}
};
// 開始加載... 假設(shè)從這里開始一個耗時的操作將開始啟動,在此啟動過程中,開發(fā)者希望用戶稍事休息,等待。。。
progressLayout.showProgress();
// 假設(shè)有一個耗時的加載業(yè)務(wù)邏輯,需要秒完成。
handler.sendEmptyMessageDelayed(, );
}
}
以上內(nèi)容是小編給大家分享的關(guān)于加載頁面遮擋耗時操作任務(wù)頁面--第三方開源之AndroidProgressLayout的全部敘述,希望大家喜歡。
- Android開發(fā)中如何解決Fragment +Viewpager滑動頁面重復(fù)加載的問題
- Android中替換WebView加載網(wǎng)頁失敗時的頁面
- Android中自定義加載樣式圖片的具體實現(xiàn)
- Android自定義加載loading view動畫組件
- Android自定義加載控件實現(xiàn)數(shù)據(jù)加載動畫
- Android自定義view實現(xiàn)阻尼效果的加載動畫
- Android自定義下拉刷新上拉加載
- Android自定義View實現(xiàn)loading動畫加載效果
- Android自定義Dialog實現(xiàn)文字動態(tài)加載效果
- Android實現(xiàn)自定義加載框的代碼示例
- Android開發(fā)實現(xiàn)自定義新聞加載頁面功能實例
相關(guān)文章
Android 取消藍牙配對框?qū)崿F(xiàn)自動配對功能
這篇文章主要介紹了Android 取消藍牙配對框?qū)崿F(xiàn)自動配對功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-02-02
Android SharedPreferences存儲的正確寫法
這篇文章主要介紹了Android SharedPreferences存儲的正確寫法的相關(guān)資料,需要的朋友可以參考下2017-06-06
android UI進階之a(chǎn)ndroid中隱藏的layout 抽屜的使用方法
android UI進階之a(chǎn)ndroid中隱藏的layout 抽屜的使用方法,需要的朋友可以參考一下2013-05-05
Android RecyclerView添加頭部和底部的方法
這篇文章主要為大家詳細介紹了Android RecyclerView添加頭部和底部的方法,感興趣的小伙伴們可以參考一下2016-05-05
Android自定義View實現(xiàn)QQ音樂中圓形旋轉(zhuǎn)碟子
這篇文章主要為大家詳細介紹了Android自定義View實現(xiàn)QQ音樂中圓形旋轉(zhuǎn)碟子,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
Android 中ListView點擊Item無響應(yīng)問題的解決辦法
如果listitem里面包括button或者checkbox等控件,默認(rèn)情況下listitem會失去焦點,導(dǎo)致無法響應(yīng)item的事件,怎么解決呢?下面小編給大家分享下listview點擊item無響應(yīng)的解決辦法2016-12-12
Android實戰(zhàn)教程第七篇之如何在內(nèi)存中存儲用戶名和密碼
這篇文章主要為大家詳細介紹了Android如何實現(xiàn)在內(nèi)存中存儲用戶名和密碼的相關(guān)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11
Android App中使用Pull解析XML格式數(shù)據(jù)的使用示例
這篇文章主要介紹了Android App中使用Pull解析XML格式數(shù)據(jù)的使用示例,Pull是Android中自帶的XML解析器,Java里也是一樣用:D需要的朋友可以參考下2016-04-04

