我的客户希望搜索栏看起来完全像这样: enter link description here 我已经确定了进展,次要进展和拇指看起来像希望,但我不知道,如何应用进展的点。 我希望这对于drawable是可行的,我不需要使用paddings或类似的东西来应用5个图像。
提前致谢。
答案 0 :(得分: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;
}
}
查询和保证金的值应根据进度的最小/最大值进行更改。