我正在嘗試修改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);
}