【问题标题】:In Android how to get how much of a finger touched the screen?在Android中如何获取手指触摸屏幕的多少?
【发布时间】:2011-12-12 05:09:22
【问题描述】:

在自定义视图中,如何获得手指触摸屏幕的程度。换句话说,要获取用户是否使用了他的指尖或更大的区域。然后能够得到矩形的每个维度。

【问题讨论】:

    标签: android screen


    【解决方案1】:

    event.getPointerCount() 方法调用为您提供触摸次数

    示例代码

    @Override
    public boolean onTouchEvent(final MotionEvent event)
    {
        System.out.println("Touch Count ="+event.getPointerCount());
    
        return true;
    }
    

    【讨论】:

    • 谢谢 Sunil,你能告诉我用两根手指触摸时如何缩放页面吗?
    【解决方案2】:

    嗨,我在我的项目中做过同样的事情,可能对某些人有用。 下面是代码:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      相关资源
      最近更新 更多