我想讓它按住屏幕移動我的矩形。監聽器將輸出提供給控制檯,但不會使屏幕無效。無效()不刷新屏幕
public class DrawView extends View{
Paint paint = new Paint();
static int x = 20;
static int y = 20;
public DrawView(Context context){
super(context);
paint.setColor(Color.GREEN);
}
@Override
public void onDraw(Canvas canvas){
canvas.drawRect(x,y,100,100,paint);
}
public void OTListener(){
setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View DrawView, MotionEvent e){
x = 100;
y = 100;
invalidate();
return false;
}
});
}
}
沒有給出什麼輸出?你怎麼援引這個? –
我沒有看到你調用'OTListener()'調用'setOnTouchListener()'的位置。你是否在其他地方叫它,或者你忘了叫它? – jgriffin