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