我写了一个Android多点触控的程序,当时在真机上一直不能达到多点触控的效果,一直是单点触控,而且event.getPointerCount()返回的也一直是1。
onTouch的返回值设了false或者true都不能达到要求,希望高人指点一下啊。以下是代码
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
int pointcounts = event.getPointerCount();
System.out.println(pointcounts);
//if(event.getAction() == MotionEvent.ACTION_DOWN)
int action = event.getAction() & MotionEvent.ACTION_MASK;
if(action == MotionEvent.ACTION_DOWN)
{
for(int i=0;i<pointcounts;++i)
{
//event.getPointerId(i);
int x = (int) event.getX(i);
int y = (int) event.getY(i);
if(x<50+hp1.width && x>50 && y<hp1.top1+hp1.width && y>hp1.top1)
{
tv1.setText(Integer.valueOf(pointcounts).toString());
}

if(x<50+hp1.width && x>50 && y<hp1.top2+hp1.width && y>hp1.top2)
{
tv2.setText("Second");
}

if(x<50+hp1.width && x>50 && y<hp1.top3+hp1.width && y>hp1.top3)
{
tv3.setText("Third");
}
}
}
if(action == MotionEvent.ACTION_UP)
{
tv1.setText("NULL");
tv2.setText("NULL");
tv3.setText("NULL");
}
return true;
}
});
PS:测试的真机是支持多点触控的,系统是2.1的。