问题
In a custom view how would it be possible to get how much of a finger touched the screen. In other words, to get if the user used the tip of his finger or a larger area. And then to be able to get each dimension of the rectangle.
回答1:
event.getPointerCount()
method call gives you number of touch
Sample Code
@Override
public boolean onTouchEvent(final MotionEvent event)
{
System.out.println("Touch Count ="+event.getPointerCount());
return true;
}
回答2:
Hi I have done same thing in my project may be it is useful for some one. Below is the code:
boolean read = true;
int count = 0;
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction() & MotionEvent.ACTION_MASK;
if(action == MotionEvent.ACTION_POINTER_UP)
{
if(read == true)
{
count = event.getPointerCount();
read = false;
}
if(event.getPointerCount() == count)
{
Toast.makeText(getApplicationContext(), Integer.toString(count), Toast.LENGTH_SHORT).show();
}
}
if(action == MotionEvent.ACTION_POINTER_DOWN)
{
count = 0;
read = true;
}
return true;
}
来源:https://stackoverflow.com/questions/8470174/in-android-how-to-get-how-much-of-a-finger-touched-the-screen