0
我試圖只在按鈕被點擊時畫一個圓。要移動該圓圈,必須單擊一個按鈕才能進行移動。然而,點擊按鈕後,bclick的初始值爲false,但bclick的值始終爲真。如何使它在繪製圓圈後每次都將bclick設置爲false?Android:布爾型
我的視圖類:
@Override
public boolean onTouchEvent(MotionEvent event) {
x = event.getX();
y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (MainActivity.isButtonClicked() == true){
canvas.drawCircle(x, y, radius, paint)
invalidate();
}
break;
case MotionEvent.ACTION_MOVE:
lastx = event.getX();
lasty = event.getY();
if (MainActivity.isMoveButtonClicked() == true && Mainactivity.is ButtonCLicked() == false){
canvas.drawCircle(lastx, lasty, radius, paint)
invalidate();// if this is used, the moving is slow and doesnt move to the exact spot at (lastx, laxyy)
}
break;
}
我的MainActivity:
boolean bclick =false;
boolean mbclick =false;
drawbutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
bclick = true;
}
});
bclick = false;
movebutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mbclick = true;
}
});
mbclick = false;
public static boolean isButtonClicked() {
return bclick;
}
public static void setButtonClicked(boolean torf)
{
bclick = torf;
}
public static boolean isMoveButtonClicked() {
return mbclick;
}
public static void setMoveButtonClicked(boolean torf)
{
mbclick = torf;
}
我曾嘗試這種方法,但是當我嘗試移動圓圈(按下anot後她的按鈕)時,圓的移動變得緩慢並且不會停在最後觸摸的座標處。我用更多的代碼更新了這個。請指教謝謝。 – user3306996