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

北战南征 提交于 2020-01-03 05:10:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!