java在画布上画出变量_java – 在画布上绘画用更好的分辨率的油漆? (机器人)...

我用Canvas和Paint做了一个小装载圈.

这是我第一次尝试使用这些类,所以它可能是我错误使用的东西.

我的问题是,绘画的分辨率太低了.我可以清楚地看到像素.

我怎么能改进这个?

顺便说一下这是我的班级:

public class LoadingCircle extends LinearLayout {

public LoadingCircle(Context context, AttributeSet attrs) {

super(context, attrs);

setWillNotDraw(false);

}

// time

int countDownTime = 180;

Paint paint = new Paint();

RectF oval = new RectF();

Path path = new Path();

// value

int value = 360 / countDownTime;

// starting progress

int progress = -360 - value;

@Override

public void onDraw(Canvas canvas) {

super.onDraw(canvas);

float width = (float) getWidth();

float height = (float) getHeight();

float center_x = width / 2, center_y = height / 2;

float loadingRadius = (float) ((width / 2)*0.85);

float whiteRadius = (float) (loadingRadius * 1.06);

float greenRadius = (float) (loadingRadius * 1.14);

// **background green circle**/

oval.set(center_x - greenRadius, center_y - greenRadius, center_x + greenRadius, center_y + greenRadius);

paint.setColor(Color.parseColor("#a3d47b"));

paint.setStyle(Paint.Style.FILL_AND_STROKE);

canvas.drawArc(oval, 270, 360, true, paint);

// ****//

// **background green circle**/

oval.set(center_x - whiteRadius, center_y - whiteRadius, center_x + whiteRadius, center_y + whiteRadius);

paint.setColor(Color.parseColor("#ffffff"));

paint.setStyle(Paint.Style.FILL_AND_STROKE);

canvas.drawArc(oval, 270, 360, true, paint);

// **Loading circle**//

path.addCircle(center_x, center_y, loadingRadius, Path.Direction.CW);

paint.setColor(Color.parseColor("#71b23c"));

paint.setStyle(Paint.Style.FILL_AND_STROKE);

oval.set(center_x - loadingRadius, center_y - loadingRadius, center_x + loadingRadius, center_y + loadingRadius);

progress = progress + value;

Log.i("proges: ", progress + "");

canvas.drawArc(oval, 270, progress, true, paint);

// /**//

}

public void setCountDownTime(int time) {

this.countDownTime = time;

this.value = 360 / countDownTime;

this.progress = -360 - value;

}

// reseting loading circle

public void reset() {

this.progress = -360 - value;

this.invalidate();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值