如何显示水平 Android 不确定进度条

发布于 2024-11-16 13:04:32 字数 76 浏览 4 评论 0原文

如何在android中显示不确定的水平进度条?进度条的动画应从 0 开始到 100,然后连续从 100 回到 0。我不是在寻找滚轮进度条。

How to show an indeterminate horizontal progress bar in android? The animation of the progress bar should start from 0 to 100 and then go back from 100 to 0 continuously. I am not looking for the wheel progress bar.

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

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

发布评论

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

评论(5

逆光飞翔i 2024-11-23 13:04:32

我已经知道 setInminateate 会给出一个无限的水平进度条。但它与装载轮类似,只是它是水平的。如果你看到我的问题,我正在寻找从 0 开始一直到 100(逐渐增加)的水平条。如果你想在Android中实现这一点,你必须使用你的进度条,如下所示:

 <ProgressBar
    android:id="@+id/progress_horizontal"
    android:indeterminateOnly="false"
    android:indeterminateDrawable="@drawable/progress_indeterminate_horizontal"
    android:progressDrawable="@drawable/progress_horizontal"
    android:minHeight="24dip"
    android:maxHeight="24dip" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

由于我想改变我的进度条的背景,我改变了ProgressDrawable和InminatedDrawable。原始的可绘制对象位于frameworks/base/core/res/res/drawable下。将它们复制到您的项目中并根据您的需要更改颜色。

创建一个更新进度计数并执行 Thread.Sleep 的线程。然后它将消息发送到 Handler,该 Handler 将更新 UI 线程中的进度条。

I already knew that setIndeterminate will give an infinite horizontal progress bar. But it will be similar to the loading wheel, except that it will be horizontal. If you see my question I was looking for horizontal bar which starts from 0 and goes all the way to 100 (a gradual increase). If you want to achieve this in Android, you must use your progress bar as below:

 <ProgressBar
    android:id="@+id/progress_horizontal"
    android:indeterminateOnly="false"
    android:indeterminateDrawable="@drawable/progress_indeterminate_horizontal"
    android:progressDrawable="@drawable/progress_horizontal"
    android:minHeight="24dip"
    android:maxHeight="24dip" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

As I wanted to change the background of my progress bar, I changed the ProgressDrawable and IndeterminateDrawable. The original drawables are located under frameworks/base/core/res/res/drawable. Copy them to your project and change the color according to your needs.

Create a thread which updates the progress count and does a Thread.Sleep. Then it sends the message to the Handler which will update the progress bar in UI thread.

海螺姑娘 2024-11-23 13:04:32

使用 ProgressBar 的 setInminateate 方法:

android.widget.ProgressBar bar = new android.widget.ProgressBar(context);
bar.setIndeterminate(true);

但是,是的,您可以在开发人员文档中很快找到它。

http://developer.android.com/reference/android /widget/ProgressBar.html#setInminated%28boolean%29

Use the method setIndeterminate of ProgressBar:

android.widget.ProgressBar bar = new android.widget.ProgressBar(context);
bar.setIndeterminate(true);

But yeah, you could have found this pretty quickly in the developer docs.

http://developer.android.com/reference/android/widget/ProgressBar.html#setIndeterminate%28boolean%29

吖咩 2024-11-23 13:04:32

也许有点晚了,但你可以做这样的事情:

<ProgressBar
    android:id="@+id/progress"
    android:layout_width="match_parent"
    android:layout_height="10dp"
    android:indeterminate="true"
    style="?android:attr/progressBarStyleHorizontal" />

希望它能帮助别人!

Maybe a bit late, but you can do something like this:

<ProgressBar
    android:id="@+id/progress"
    android:layout_width="match_parent"
    android:layout_height="10dp"
    android:indeterminate="true"
    style="?android:attr/progressBarStyleHorizontal" />

Hope it helps someone!

云归处 2024-11-23 13:04:32

为了扩展 Vinoth 答案,这里有一个现成的代码:

<ProgressBar
        android:id="@+id/progressBarLoadingRecite"
        android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal"
        android:minHeight="24dip"
        android:layout_marginTop="20dip"
        android:indeterminate="true"
        android:maxHeight="24dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

To expand on Vinoth Answer, here is a ready code:

<ProgressBar
        android:id="@+id/progressBarLoadingRecite"
        android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal"
        android:minHeight="24dip"
        android:layout_marginTop="20dip"
        android:indeterminate="true"
        android:maxHeight="24dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
来世叙缘 2024-11-23 13:04:32

在定义进度条的 xml 中,您可以添加

style="@android:style/Widget.ProgressBar.Horizontal"

In the xml defining your progress bar, you can add

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