如何显示水平的 Android 不确定进度条 [英] How to show a Horizontal Android Indeterminate Progress Bar

查看:33
本文介绍了如何显示水平的 Android 不确定进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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.

推荐答案

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

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

因为我想更改进度条的背景,所以我更改了 ProgressDrawable 和 IndeterminateDrawable.原始 drawable 位于 frameworks/base/core/res/res/drawable 下.将它们复制到您的项目中并根据您的需要更改颜色.

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.

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

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.

这篇关于如何显示水平的 Android 不确定进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆