android画布画弧形,在android画布上,绘制斜角矩形/圆弧_android_开发99编程知识库...

我正在嘗試修改android設備的遊戲桿組件。 目前該組件能夠跟蹤你的手指的x 和y 位置,並在那裡畫一個小圓圈。 我想做的是從中心到你手指的x 和y 位置畫一個 rectangle 或者 arc 。

只是我知道 rectangle 只接受頂部,左邊,右邊的值,只允許我在水平或者垂直方向繪製矩形。 如果有人知道另一種方法來繪製這將是非常棒的。

儘管現在我想使用drawArc函數得到一個直線,但是現在我想用函數來繪製 rectangle 曲線,這是一個參數參數。

我當前使用的代碼是:@Override

protected void onDraw(Canvas canvas) {

int centerX = (getWidth())/2;

int centerY = (getHeight())/2;

Paint p = new Paint();

p.setColor(buttonColor);

RadialGradient gradient = new RadialGradient( centerX, centerY, joystickRadius,

backgroundColor,circleColor, android.graphics.Shader.TileMode.CLAMP);

//draw an outer circle

p.setDither(true);

p.setShader(gradient);

canvas.drawCircle( (int) centerX, (int) centerY, joystickRadius, p);

p.setShader(null);

p.setColor(buttonColor);

p.setStyle(Paint.Style.FILL);

//draw the joystick thumbpad

canvas.drawCircle(x, y, buttonRadius, p);

//draw a line from the centre of outer circle to the center of the

//thumbpad. I want this to be a curved rectangle instead.

canvas.drawLine( centerX, centerY, x, y, p);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值