【问题标题】:How to check how many fingers touch the screen in Android?如何在Android中检查有多少手指触摸屏幕?
【发布时间】:2019-11-06 09:31:24
【问题描述】:

如何创建始终包含触摸屏幕的手指数量的(可全局访问的)变量?

谢谢

 int counter;

         public boolean onTouch(View v, MotionEvent event) {
         switch(event.getActionMasked()) { 
           case MotionEvent.ACTION_DOWN: 

             `enter code here`
         break; 
         case MotionEvent.ACTION_POINTER_DOWN:

               `enter code here`

        break;
        case MotionEvent.ACTION_MOVE: 

          `enter code here`

         break;          
        case MotionEvent.ACTION_POINTER_UP:

           `enter code here`

        break; 
        case MotionEvent.ACTION_UP:  

            `enter code here




   }
     return true;  
    }   

【问题讨论】:

    标签: android android-studio touch touch-event


    【解决方案1】:

    MotionEvent查看getPointerCount方法

    int counter;
    
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        counter = event.getPointerCount();
        switch(event.getActionMasked()) { // if still needed
        ...
    

    【讨论】:

    • 在每个“案例”条件中我应该添加:counter= event.getPointerCount()?
    • 不,你可以在任何时候使用它,甚至在switch.. case 声明之前(检查编辑)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多