0
當我無法獲得ontouch(Canvas對象)在畫布上繪製,沒有畫布,我不能畫一個圓,當touched.How觸摸時可我畫任何形狀或圖像如何感動
public class Board extends View implements View.OnTouchListener {
public Board(Context context) {
super(context);
Paint paint1 = new Paint();
paint1.setTextSize(50);
paint1.setColor(Color.WHITE);
View view=this;
view.setOnTouchListener(this);
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRGB(200, 100, 0);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
final int action = MotionEventCompat.getActionMasked(event);
int pointer = MotionEventCompat.getActionIndex(event);
if (action == MotionEvent.ACTION_DOWN) {
canvas.drawCircle(70, 1100, 50, paint1);
}
return false;
}
'Canvas'不是一個本地或全局對象,所以你不能從'onTouch()'事件訪問它。可以在此方法上創建Canvas實例或使用Global。 – Riad
[Draw Circle on touch]的可能重複(http://stackoverflow.com/questions/11796357/draw-circle-on-touch) – 0X0nosugar