1
我對自定義視圖畫布有這個問題:自定義視圖畫布
1-如何在更改後重置視圖?這是我的代碼,但沒有任何反應
@Override
protected void onDraw(Canvas canvas) {
int viewWidthHalf = this.getMeasuredWidth()/2;
int viewHeightHalf = this.getMeasuredHeight()/2;
int radius;
if (viewWidthHalf > viewHeightHalf)
radius = viewHeightHalf - 10;
else
radius = viewWidthHalf - 10;
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setColor(backgroundColor);
canvas.drawCircle(viewWidthHalf, viewHeightHalf, radius, paint);
}
public void setbackground(int backgroundColor) {
this.backgroundColor = backgroundColor;
invalidate();
}
2 - 如何獲得其他方法的畫布?
3 - 當我用drawCircle圈上面的代碼有一個0.3-0.4的alpha。爲什麼?
invalidate();沒有改變圓的顏色和保護無效onDraw()你寫的代碼似乎不正確 –
你給backgroundColor變量什麼值? –
解決了謝謝:) –