【发布时间】:2016-10-29 05:23:29
【问题描述】:
【问题讨论】:
【问题讨论】:
以下是我在基本级别上所做的。你需要让它充满活力才能品尝:
public class SegmentedSeekBar extends android.support.v7.widget.AppCompatSeekBar {
private Paint progressPaint;
public SegmentedSeekBar(Context context) {
super(context);
init();
}
public SegmentedSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public SegmentedSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
progressPaint = new Paint();
progressPaint.setStyle(Paint.Style.FILL_AND_STROKE);
progressPaint.setColor(Color.LTGRAY);
progressPaint.setStrokeWidth(2.0f);
}
@Override
protected synchronized void onDraw(Canvas canvas) {
int halfHeight = getHeight() / 2;
int pos;
float smallH = 10;
float div = (getWidth() - getPaddingRight() - getPaddingLeft()) / (getMax());
for (int i = 1; i < getMax(); i++) {
pos = (int) (div * i) + getPaddingLeft();
canvas.drawLine(
pos + 1.0f,
halfHeight - (halfHeight / 2.0f),
pos + 1.0f,
halfHeight + (halfHeight / 2.0f),
progressPaint);
}
super.onDraw(canvas);
}
}
【讨论】:
完成您的要求的最佳方法是在搜索栏上添加空视图(3 视图)。使用 match_parent 高度创建视图,2dp 宽度在搜索栏上。
更多信息见链接Seek bar with divider
【讨论】: