重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本文实例讲述了Android编程实现两点触控功能。分享给大家供大家参考,具体如下:
成都创新互联公司云计算的互联网服务提供商,拥有超过13年的服务器租用、成都二枢服务器租用托管、云服务器、虚拟主机、网站系统开发经验,已先后获得国家工业和信息化部颁发的互联网数据中心业务许可证。专业提供云主机、虚拟主机、域名注册、VPS主机、云服务器、香港云服务器、免备案服务器等。下面是一个两点触控的案例代码:
package com.zzj; import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; public class AndroidTestActivity extends Activity { private float x0, y0; private float x1, y1; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public boolean onTouchEvent(MotionEvent event) { int pointerCount = event.getPointerCount(); int action = event.getAction(); if (pointerCount == 1) { switch (action) { case MotionEvent.ACTION_DOWN: x0 = event.getX(0); y0 = event.getY(0); System.out.println("ACTION_DOWN pointerCount=" + pointerCount); break; case MotionEvent.ACTION_UP: System.out.println("ACTION_UP pointerCount=" + pointerCount); break; case MotionEvent.ACTION_MOVE: System.out.println("ACTION_MOVE pointerCount=" + pointerCount); break; } } if (pointerCount == 2) { switch (action) { case MotionEvent.ACTION_DOWN: x0 = event.getX(0); y0 = event.getY(0); System.out.println("ACTION_DOWN pointerCount=" + pointerCount); break; case MotionEvent.ACTION_UP: System.out.println("ACTION_UP pointerCount=" + pointerCount); break; case MotionEvent.ACTION_MOVE: System.out.println("ACTION_MOVE pointerCount=" + pointerCount); break; case MotionEvent.ACTION_POINTER_1_DOWN: System.out.println("ACTION_POINTER_1_DOWN pointerCount=" + pointerCount); break; case MotionEvent.ACTION_POINTER_1_UP: System.out.println("ACTION_POINTER_1_UP pointerCount=" + pointerCount); break; case MotionEvent.ACTION_POINTER_2_DOWN: System.out.println("ACTION_POINTER_2_DOWN pointerCount=" + pointerCount); break; case MotionEvent.ACTION_POINTER_2_UP: System.out.println("ACTION_POINTER_2_UP pointerCount=" + pointerCount); break; } } return super.onTouchEvent(event); } }