Android 我不能在进度条上画圆边
我在程序中创建自定义进度。 但我不能创建半圆零件。我想创建类似进度的零件,这是在顶部框的图片中选择的 我的代码:Android 我不能在进度条上画圆边,android,android-canvas,Android,Android Canvas,我在程序中创建自定义进度。 但我不能创建半圆零件。我想创建类似进度的零件,这是在顶部框的图片中选择的 我的代码: public class SemiCircleProgressBarView extends View { private Path mClippingPath; private float mPivotX; private float mPivotY; private Context context; private float pro
public class SemiCircleProgressBarView extends View {
private Path mClippingPath;
private float mPivotX;
private float mPivotY;
private Context context;
private float progress = 0.0f;
private float thickness;
public SemiCircleProgressBarView(Context context) {
super(context);
this.context = context;
initializeImage();
}
public SemiCircleProgressBarView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
initializeImage();
}
private void initializeImage() {
mClippingPath = new Path();
mPivotX = 0;
mPivotY = 0;
}
public void setClipping(float progress) {
this.progress = progress;
mClippingPath.reset();
thickness = 0.25f * getHeight();
mClippingPath.setFillType(Path.FillType.INVERSE_WINDING);
mClippingPath.addCircle(0.5f * getWidth(), getHeight(), getHeight() - thickness, Path.Direction.CCW);
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float angle = (progress * 180) / 100;
RectF oval = new RectF(mPivotX, mPivotY, mPivotX + getWidth(), mPivotY + 2.0f * getHeight());
Paint p = new Paint();
p.setColor(context.getResources().getColor(R.color.progress));
Paint pbg = new Paint();
pbg.setColor(context.getResources().getColor(R.color.progress_bg));
// Paint cr = new Paint();
// cr.setColor(Color.RED);
canvas.clipPath(mClippingPath);
canvas.drawArc(oval, 180, 360, true, pbg);
canvas.drawArc(oval, 180, angle, true, p);
// canvas.drawCircle(0.5f * thickness,getHeight(),30,cr);
double radAngle = Math.toRadians(angle);
float px = getWidth () - (float)Math.cos(radAngle) * ((float)getWidth() - thickness);
float py = getHeight() - (float)Math.sin(radAngle) * ((float)getHeight() - 0.5f * thickness);
canvas.drawCircle(0.5f * px, py, 0.5f * thickness, p);
}
}
底部选择矩形中的部分将在顶部选择矩形中同步进行检查答案@ip696如果您愿意,请向上投票,…我需要在我的qestion中的图像上同步进行。半圆。一半。我认为您需要半旋转未满的循环进度,…使用油漆#设置行程上限(油漆。上限。圆形)作为@pskink pbg。设置行程上限(油漆。上限。圆形);