如何为此自定义Seekbar提供图像?

时间:2017-09-26 05:15:11

标签: android android-seekbar

我想做一个像这样的搜索栏:

timer

我尝试了很少这样的库:

https://github.com/tankery/CircularSeekBarhttps://github.com/devadvance/circularseekbar

但我无法实现我想要的目标。

我有这个搜索栏的图像,我们可以从drawarc或任何其他想法中获得任何东西吗?

EDIT(28/09/2017)::

尝试了这段代码,但无法获得结果:

public class CustomView extends View{

Bitmap gold,grey;
Paint paint;
Context context;
int progress=0;
private Paint mPaint,mPaint2;
private RectF mOval,mOval2;


public CustomView(Context context) {
    super(context);
    init(context);
}

public CustomView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    init(context);
}

public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init(context);
}

public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    init(context);
}


public void init(Context context)
{
    this.context = context;
    paint = new Paint();
    gold = BitmapFactory.decodeResource(context.getResources(),
            R.drawable.timer_golden_full);

    grey = BitmapFactory.decodeResource(context.getResources(),
            R.drawable.timer_greyline);

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mOval = new RectF();
    Matrix m = new Matrix();
    RectF src = new RectF(0, 0, gold.getWidth(), gold.getHeight());
    RectF dst = new RectF(0, 0, 200, 250);
    m.setRectToRect(src, dst, Matrix.ScaleToFit.CENTER);
    Shader shader = new BitmapShader(gold, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    shader.setLocalMatrix(m);
    mPaint.setShader(shader);
    m.mapRect(mOval, src);

    mPaint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
    mOval2 = new RectF();
    Matrix m2 = new Matrix();
    RectF src2 = new RectF(0, 0, gold.getWidth(), gold.getHeight());
    RectF dst2 = new RectF(0, 0, 200, 250);
    m2.setRectToRect(src2, dst2, Matrix.ScaleToFit.CENTER);
    Shader shader2 = new BitmapShader(grey, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    shader2.setLocalMatrix(m2);
    mPaint2.setShader(shader2);
    m2.mapRect(mOval2, src2);
}



public void update()
{

}
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.drawArc(mOval2, 0, 360, true, mPaint2);
    canvas.drawArc(mOval, 0, 360, true, mPaint);


}

}

0 个答案:

没有答案