本文實例講述了Android編程實現(xiàn)兩點觸控功能。分享給大家供大家參考,具體如下:
下面是一個兩點觸控的案例代碼:
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); } }
分享文章:Android編程實現(xiàn)兩點觸控功能示例-創(chuàng)新互聯(lián)
當前網(wǎng)址:http://www.chinadenli.net/article24/gigje.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、商城網(wǎng)站、外貿(mào)網(wǎng)站建設、定制網(wǎng)站、域名注冊、網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容