gpt4 book ai didi

android - 我如何设计带有点的 android 搜索栏

转载 作者:行者123 更新时间:2023-11-29 15:22:29 25 4
gpt4 key购买 nike

我的客户希望有一个看起来完全像这样的搜索栏: enter link description here我已经设置了进度、次要进度和拇指的样式,使其看起来如愿,但我不知道如何在进度上应用这些点。我希望这可以通过 drawable 实现,并且我不必应用 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 的值应根据进度的最小/最大值进行更改。

关于android - 我如何设计带有点的 android 搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16959515/

25 4 0