How to make a progress bar use an image to show progress instead of using a color in Android

大兔子大兔子 提交于 2019-12-11 06:59:23

问题


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.

Can be done?


回答1:


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>

Then in the onProgress just call yourDrawable.setLevel(progressAmount)




回答2:


Try to use:

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


来源:https://stackoverflow.com/questions/6781675/how-to-make-a-progress-bar-use-an-image-to-show-progress-instead-of-using-a-colo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!