【问题标题】:How to make a progress bar use an image to show progress instead of using a color in Android如何使进度条使用图像来显示进度而不是在 Android 中使用颜色
【发布时间】:2011-07-21 19:33:30
【问题描述】:

我想在进度条中使用一个徽标图像。每次下载图像时,我的进度条都会使用蓝色条上升。但是,我希望它慢慢地显示我的徽标图像,一次一点。我试过了:

android:progressDrawable="@drawable/logo"

但这只是将整个进度条立即设置为我的图像。我还尝试使用以下方法动态设置它:

progressBar.setProgressDrawable(getResources()...etc)

但这只是让我没有视野和黑色的空白空间。

可以吗?

【问题讨论】:

标签: android image progress-bar drawable


【解决方案1】:

创建一个ClipDrawable 并在 XML 中设置你的 progressDrawable 以指向看起来像这样的 ClipDrawable XML:

<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/logo"
    android:clipOrientation="horizontal"
    android:gravity="left" />
</clip>

然后在 onProgress 中调用yourDrawable.setLevel(progressAmount)

【讨论】:

  • 我试过了,但我的应用程序崩溃了。我收到此错误:07-21 15:14:38.492: ERROR/AndroidRuntime(30806): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class android.widget.ProgressBar 有什么想法吗?谢谢。
  • 它不应该崩溃,它与android:progressDrawable="@drawable/logo" 完全相同,只是drawable 是ClipDrawable...
  • 好吧,我使用 完全一样,但参考了我的可绘制对象。有什么想法吗?
  • 你有没有把你的进度条设置成水平的,像这样:style="@android:style/Widget.ProgressBar.Horizo​​ntal"
  • 我的设置是这样的:style="?android:attr/progressBarStyleHorizo​​ntal".
【解决方案2】:

尝试使用:

progressBar.setIndeterminateDrawable(getResources()...etc)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2011-01-02
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    相关资源
    最近更新 更多