gpt4 book ai didi

android - 带分隔线的进度条

转载 作者:太空宇宙 更新时间:2023-11-03 11:48:48 25 4
gpt4 key购买 nike

谁能给我解释一下如何实现带有分隔线的进度条,如下图所示?

enter image description here

进度条我用的是https://github.com/akexorcist/Android-RoundCornerProgressBar但这似乎没有分隔选项。

最佳答案

替换我的 answer 中的 ProgressDrawable修改后的:

class ProgressDrawable extends Drawable {
private static final int NUM_SEGMENTS = 4;
private final int mForeground;
private final int mBackground;
private final Paint mPaint = new Paint();
private final RectF mSegment = new RectF();

public ProgressDrawable(int fgColor, int bgColor) {
mForeground = fgColor;
mBackground = bgColor;
}

@Override
protected boolean onLevelChange(int level) {
invalidateSelf();
return true;
}

@Override
public void draw(Canvas canvas) {
float level = getLevel() / 10000f;
Rect b = getBounds();
float gapWidth = b.height() / 2f;
float segmentWidth = (b.width() - (NUM_SEGMENTS - 1) * gapWidth) / NUM_SEGMENTS;
mSegment.set(0, 0, segmentWidth, b.height());
mPaint.setColor(mForeground);

for (int i = 0; i < NUM_SEGMENTS; i++) {
float loLevel = i / (float) NUM_SEGMENTS;
float hiLevel = (i + 1) / (float) NUM_SEGMENTS;
if (loLevel <= level && level <= hiLevel) {
float middle = mSegment.left + NUM_SEGMENTS * segmentWidth * (level - loLevel);
canvas.drawRect(mSegment.left, mSegment.top, middle, mSegment.bottom, mPaint);
mPaint.setColor(mBackground);
canvas.drawRect(middle, mSegment.top, mSegment.right, mSegment.bottom, mPaint);
} else {
canvas.drawRect(mSegment, mPaint);
}
mSegment.offset(mSegment.width() + gapWidth, 0);
}
}

@Override
public void setAlpha(int alpha) {
}

@Override
public void setColorFilter(ColorFilter cf) {
}

@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
}

然后像这样创建它:

Drawable d = new ProgressDrawable(0xdd00ff00, 0x4400ff00);

关于android - 带分隔线的进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30868393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com