有多种颜色搜索栏或进度条 [英] Seekbar or progress bar with multiple colors

查看:225
本文介绍了有多种颜色搜索栏或进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于有多种颜色搜索栏或进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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