有多种颜色搜索栏或进度条有多、种颜色、进度条

2023-09-05 07:58:35 作者:悟红尘

我要创建这样的最初一棒时,进度零这将是颜色的褪色,但并作为进度的推移它会成为光明的那一部分(这是最好的,我可以解释),最主要的是我想吧以显示所有颜色同时

I want to create a bar like this initially when progress is zero it will be a fade in color but and as progress goes on it will become bright on that part(This is best I can explain) main thing is i want bar to show all colors at the same time.

推荐答案

剪辑的上绘制: 在你的关绘制:

Clip your "on" drawable: over your "off" drawable:

使用 RES /绘制/ custom_progress_drawable.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@android:id/background"
        android:drawable="@drawable/custom_progress_bar_off"/>
    <item android:id="@android:id/progress">
        <clip android:drawable="@drawable/custom_progress_bar_on" />
    </item>

</layer-list>

MyProgressBar.java

public class MyProgressBar extends ProgressBar {

    public MyProgressBar(Context context) {
        this(context, null);
    }

    public MyProgressBar(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyProgressBar(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setProgressDrawable(context.getResources().getDrawable(R.drawable.custom_progress_drawable));
    }
}

在这里,使用机器人时的结果:在XML最大=10

这是一个有点过,但你可以使用 SETMAX()的东西更像是百万,并做一些打电话时偏移计算 setProgress()来使之清洁。

It's a little bit off, but you could use setMax() with something more like 1000000 and do some offsetting calculations when calling setProgress() to make it cleaner.