我想要一个进度圈而不是进度对话框

发布于 2024-10-21 03:04:16 字数 87 浏览 6 评论 0原文

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

I want to show a progress Circle in my app while loading data. I have an activity and moving from one activity to another I am parsing some xml data so for the time being until the parsing is completed I want to show a circular loading effect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

相守太难 2024-10-28 03:04:16

您可以使用不确定的 ProgressBar 来实现循环加载效果。以下是在 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

You can use an indeterminate ProgressBar for the circular loading effect. Here is how you do it in 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"/>

You can change the height and width to be what you want. When you are done loading, you can change it's visibility to View.INVISIBLE or View.GONE

为你鎻心 2024-10-28 03:04:16

您需要在 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" />

You need to create animation xml file in res/anim folder and call startAnimation in your ImageView when you are loading data and stopAnimation when you stop loading data. And set loading image to ImageView, for example:

loading

This id code for circle animation xml file

<?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" />
醉南桥 2024-10-28 03:04:16

将此插入两个 View 标签之间

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

Insert this beetween two View tags

<ProgressBar android:id="@+id/loading_spinner"
        style="?android:progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />
染墨丶若流云 2024-10-28 03:04:16

为什么不使用进度条 UI

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

dan

Why not use the progressbar UI

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

dan

情绪 2024-10-28 03:04:16

使用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);


    }
  }

Use AsyncTask for loading and parsing:

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


    }
  }
琉璃繁缕 2024-10-28 03:04:16

就像进度对话框一样,使用动画代替异步任务,并使其在执行前可见并在执行后再次隐藏。

Just as you would the progress dialog, use an animation instead with async task and just make it visible on prexecution and hide it again on post.

偷得浮生 2024-10-28 03:04:16

要扩展 trgraglia 的答案,您可以创建一个不确定的(行为:循环)进度条并将可见性设置为 false。在 AsyncTask preExecute() 期间,使其可见,并在 AsyncTask onPostExecute() 期间,将其恢复为不可见(前提是您处于同一活动或您可能需要的情况)。这消除了创建动画的需要。

To expand a bit on trgraglia's answer, you could create an indeterminate (behavior: cycle) progress bar and set the visibility to false. During AsyncTask preExecute(), make it visible, and during AsyncTask onPostExecute(), turn it back to invisible (provided you are staying on the same activity or w/e case you may need). This eliminates the need to create an animation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文