我想在加載數據時在我的應用程序中顯示一個進度環。我有一個活動,並從一個活動移動到另一個我解析一些XML數據,所以暫時解析完成後,我想顯示一個循環加載效果。我想要一個進度圈而不是進度對話框
回答
爲什麼當加載數據和stopAnimation不使用進度UI
myProgressDialog = ProgressDialog.show(ListingPage.this,"Please Wait", "Loading Date", true);
丹
我不能使用這個progressDialog因爲我的客戶不想要這個,他想要循環加載效果。 – ta54 2011-03-10 12:43:35
*** ProgressDialog現已棄用。 – Digitalsa1nt 2017-11-02 13:51:59
您需要創建在res /動畫文件夾的動畫XML文件,並調用startAnimation在您的ImageView當你停止加載數據。並設置加載圖像的ImageView,例如:
loading http://bigod26.com/pics/loading.png
這對圈動畫xml文件的ID碼
<?xml version="1.0" encoding="UTF-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:duration="1200"
android:interpolator="@android:anim/linear_interpolator" />
正如你的進度對話框,使用動畫與替代異步任務只需在預執行時將其顯示出來並在帖子上再次隱藏即可。
使用的AsyncTask加載和解析:
/**
* Background task that fetched the content from server and parses the content.
*/
private class BackgroundLoadingTask extends AsyncTask<InputStream, Void, Boolean> {
@Override
protected void onPreExecute() {
// show the progress bar
Activity.this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
Activity.this.requestWindowFeature(Window.PROGRESS_VISIBILITY_ON);
}
@Override
protected Boolean doInBackground(InputStream... params) {
// try to load XML from HTTP server and parse
return true;
}
@Override
protected void onPostExecute(Boolean parsingError) {
// hide the progress bar
Activity.this.requestWindowFeature(Window.PROGRESS_VISIBILITY_OFF);
}
}
您可以使用一個不確定的進度爲循環負載效應。這裏是你如何在XML中做到這一點:
<ProgressBar android:indeterminate="true"
android:layout_width="50dp" android:layout_height="50dp"
android:id="@+id/marker_progress" style="?android:attr/progressBarStyle"
android:layout_gravity="center_vertical|center_horizontal"/>
你可以改變高度和寬度是你想要的。當你完成加載後,你可以改變它對View.INVISIBLE或View.GONE的可見性
要擴大trgraglia的答案,你可以創建一個不確定的(行爲:循環)進度條並將可見性設置爲false。在AsyncTask preExecute()期間,使其可見,並且在AsyncTask onPostExecute()期間,將其恢復爲不可見(假設您保留在相同的活動或需要的情況下)。這消除了創建動畫的需要。
插入此beetween兩個View標籤
<ProgressBar android:id="@+id/loading_spinner"
style="?android:progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
- 1. 進度對話框不要移動
- 2. 自定義對話框 - 登錄 - 我想要「模態」進度條
- 3. 進度對話框
- 4. 進度對話框
- 5. 更新進度對話框
- 6. 解散進度對話框
- 7. Android進度對話框
- 8. BlackBerry進度對話框
- 9. IFileOperation和進度對話框
- 10. Android進度對話框
- 11. Asynctask進度對話框
- 12. 進度對話框問題
- 13. 更新進度對話框
- 14. 線程進度對話框
- 15. 進度下載對話框
- 16. 的Android不確定的進度對話框進度條樣式
- 17. 多進程的Android進度對話框
- 18. Asynctask不更新進度對話框publishprogress
- 19. 進度對話框將不會顯示
- 20. 進度對話框不顯示在Android?
- 21. 進度對話框不顯示
- 22. 進度對話框顯示不
- 23. Android:進度對話框不起作用
- 24. Android - 進度對話框不關閉
- 25. Android:進度對話框不顯示
- 26. 安卓進度對話框不顯示
- 27. 進度對話框不工作
- 28. Android使用多個進度對話框
- 29. Android定位進度對話框或自定義進度對話框
- 30. Android進度對話框直接進入100%,而上傳文件
這是我做到了http://stackoverflow.com/questions/19655715/progress-dialog-is-closed-when-touch-on-screen/ 22939109#22939109 – Ali 2014-04-29 09:45:15