如何使一个进度条,用图像来显示进度,而不是在Android中使用的颜色 [英] How to make a progress bar use an image to show progress instead of using a color in Android
问题描述
我有,我想在我的进度条使用的标志形象。每个图像被下载一次,我的进度条小兵使用蓝条。不过,我想preFER,它慢慢地显示我的标志形象,一次一位。我想:
I have a logo image that I would like to use in my progress bar. Each time an image is downloaded, my progress bar creeps up using a blue bar. However, I would prefer that it slowly display my logo image, one bit at a time. I tried:
android:progressDrawable="@drawable/logo"
但只是立即设置整个进度条到我的形象。我也试图与动态设置的:
but that just set the entire progress bar immediately to my image. I also tried setting it dynamically with:
progressBar.setProgressDrawable(getResources()...etc)
不过这只是我留下了没有视图和一个黑色的空白区域。
but this just left me with no view and a black empty space.
可以做什么?
推荐答案
创建的 ClipDrawable 并设置XML的progressDrawable为指向ClipDrawable XML这看起来是这样的:
Create a ClipDrawable and set your progressDrawable in XML to point to that ClipDrawable XML which looks something like this:
<?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)
这篇关于如何使一个进度条,用图像来显示进度,而不是在Android中使用的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!