1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener { TextView txvnInfo; GestureDetectorCompat gdcInfo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txvnInfo = findViewById(R.id.txvInfo); gdcInfo = new GestureDetectorCompat(this,this); gdcInfo.setOnDoubleTapListener(this); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | @Override public boolean onTouchEvent(MotionEvent event) { gdcInfo.onTouchEvent(event); return super.onTouchEvent(event); } @Override public boolean onSingleTapConfirmed(MotionEvent e) { txvnInfo.setText("onSingleTapConfirmed : " + e.toString()); return false; } @Override public boolean onDoubleTap(MotionEvent e) { txvnInfo.setText("onDoubleTap : " + e.toString()); return false; } @Override public boolean onDoubleTapEvent(MotionEvent e) { txvnInfo.setText("onDoubleTapEvent : " + e.toString()); return false; } @Override public boolean onDown(MotionEvent e) { txvnInfo.setText("onDown : " + e.toString()); return false; } @Override public void onShowPress(MotionEvent e) { txvnInfo.setText("onDown : " + e.toString()); } @Override public boolean onSingleTapUp(MotionEvent e) { txvnInfo.setText("onSingleTapUp : " + e.toString()); return false; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { txvnInfo.setText("onScroll : " + e1.toString() + " " + e2.toString()); return false; } @Override public void onLongPress(MotionEvent e) { txvnInfo.setText("onLongPress : " + e.toString()); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { txvnInfo.setText("onFling : " + e1.toString() + " " + e2.toString()); return false; } } |
專案下載:https://ibf.tw/VMZ1s
影片教學:
沒有留言:
張貼留言