Android 我想要一个进度循环,而不是进度对话框

Android 我想要一个进度循环,而不是进度对话框,android,progress,Android,Progress,我想在加载数据时在我的应用程序中显示一个进度圈。我有一个活动,从一个活动移动到另一个活动,我正在解析一些xml数据,因此在解析完成之前,我希望显示循环加载效果。为什么不使用progressbar UI myProgressDialog = ProgressDialog.show(ListingPage.this,"Please Wait", "Loading Date", true); dan您需要在res/anim文件夹中创建动画xml文件,并在加载数据时调用ImageView中的star

我想在加载数据时在我的应用程序中显示一个进度圈。我有一个活动,从一个活动移动到另一个活动,我正在解析一些xml数据,因此在解析完成之前,我希望显示循环加载效果。

为什么不使用progressbar UI

myProgressDialog = ProgressDialog.show(ListingPage.this,"Please Wait", "Loading Date", true);


dan

您需要在res/anim文件夹中创建动画xml文件,并在加载数据时调用ImageView中的startAnimation,在停止加载数据时调用stopAnimation。并将加载图像设置为ImageView,例如:

此id代码用于圆动画xml文件

<?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" />


就像在“进度”对话框中一样,使用动画代替异步任务,只需在执行前将其显示,然后在执行后将其再次隐藏。

使用异步任务加载和解析:

 /**
   * 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);


    }
  }
/**
*从服务器获取内容并解析内容的后台任务。
*/
私有类BackgroundLoadingTask扩展异步任务{
@凌驾
受保护的void onPreExecute(){
//显示进度条
Activity.this.requestWindowFeature(Window.FEATURE\u不确定\u进度);
Activity.this.requestWindowFeature(Window.PROGRESS\u VISIBILITY\u ON);
}
@凌驾
受保护的布尔doInBackground(InputStream…参数){
//尝试从HTTP服务器加载XML并进行解析
返回true;
}
@凌驾
受保护的void onPostExecute(布尔parsingError){
//隐藏进度条
Activity.this.requestWindowFeature(Window.PROGRESS\u VISIBILITY\u 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

要在Trgaglia的答案上展开一点,可以创建一个不确定的(行为:循环)进度条,并将可见性设置为false。在AsyncTask preExecute()期间,将其设置为可见,在AsyncTask onPostExecute()期间,将其设置为不可见(前提是您使用相同的活动或您可能需要的w/e案例)。这样就无需创建动画。

在两个视图标记之间插入此项

<ProgressBar android:id="@+id/loading_spinner"
        style="?android:progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />


我无法使用此progressDialog,因为我的客户端不需要它,他需要循环加载效果。***progressDialog现在已被弃用。我正在使用带有自定义适配器的列表视图。我想在列表视图中显示加载效果。我如何才能得到解析完成,我们可以停止这个动画我也使用列表视图。当另一个线程解析xml时,我设置为lost view special loadingAdapter,它只返回一个视图。此视图为imageView,用于填充所有父视图并将图像调整到中心。当解析线程停止解析时,我将设置为“最少查看”我的另一个自定义适配器,它提供UI元素。你能给我一个使用它的示例吗。谢谢请注意,如果您全屏显示或隐藏了标题栏,则并非所有这些功能都能正常工作。
android.util.AndroidRuntimeException:requestFeature()必须在添加内容之前调用。
我就是这样做的