enter image description here 我正在制作candycrush类型的游戏进行演示。我想要滑动到图像
我遇到了使用ontouchlistner方法的问题,也想像在candycrush游戏中一样滑动到图像。
private void reset() {
for (int i = 0; i<r;i++)
{
for (int j = 0; j <c; j++)
{
Random rn = new Random();
int answer = rn.nextInt(5) + 1;
cell[i][j].setImageResource(candy[answer]);
cell[i][j].isClickable();
cell[i][j].setOnTouchListener(this);
}
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
boolean b;
if(event.getAction() == MotionEvent.ACTION_UP){
b =true;
Toast.makeText(this, "touched", Toast.LENGTH_SHORT).show();
Log.d("path>>>",b+"");
// Do what you want
return true;
}
if(event.getAction() == MotionEvent.ACTION_BUTTON_PRESS){
Toast.makeText(this, "pressed", Toast.LENGTH_SHORT).show();
b=false;
Log.d("path>>>", b + "");
// Do what you want
return true;
}
if(event.getAction() == MotionEvent.ACTION_HOVER_ENTER){
Toast.makeText(this, "hovered", Toast.LENGTH_SHORT).show();
b=false;
Log.d("path>>>", b + "");
// Do what you want
return true;
}
if(event.getAction() == MotionEvent.ACTION_BUTTON_RELEASE){
Toast.makeText(this, "button release", Toast.LENGTH_SHORT).show();
b=true;
Log.d("path>>>", b + "");
return true;
}
return true;
}