简体   繁体   中英

In Android how to get how much of a finger touched the screen?

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.

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;
}

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;        
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM