我如何用点来设计一个android搜索栏?



我的客户希望有一个搜索栏看起来完全像这样:在这里输入链接描述我已经设计了进度,次要进度和拇指看起来像我希望的那样,但我不知道如何在进度上应用点。我希望这是可行的与一个可绘制的,我不需要应用5图像与填充或类似的东西。

终于解决了。也许其他人会需要这个。我继承了原来的类,并改变了onDraw:

public class SeverityBar extends SeekBar {
private Paint selected, unselected;
private int halfSize = 15;
private RectF position;
public SeverityBar(Context context) {
    super(context);
    selected = new Paint(Paint.ANTI_ALIAS_FLAG);
    selected.setColor(getContext().getResources().getColor(R.color.TextColor));
    selected.setStyle(Style.FILL);
    unselected = new Paint(Paint.ANTI_ALIAS_FLAG);
    unselected.setColor(getContext().getResources().getColor(android.R.color.darker_gray));
    selected.setStyle(Style.FILL);
    position = new RectF();
}
@Override
protected synchronized void onDraw(Canvas canvas) {
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    float margin = (canvas.getWidth()-(paddingLeft+getPaddingRight()))/4;
    float halfHeight = (canvas.getHeight()+paddingTop)*.5f;
    for (int i = 0; i < 5; i++) {
        position.set(
                paddingLeft+(i*margin)-halfSize, 
                halfHeight-halfSize, 
                paddingLeft+(i*margin)+halfSize,
                halfHeight+halfSize);
        canvas.drawOval(position, (i<getProgress())?selected:unselected);
    }
    super.onDraw(canvas);
}
public int getDotsSize() {
    return halfSize*2;
}
public void setDotsSize(int dotsSize) {
    this.halfSize = dotsSize/2;
}

}

for query和margin的值应该根据进度的最小/最大值来改变

相关内容

  • 没有找到相关文章

最新更新