フリック動作で画面遷移
GestureDetecotorクラスのインスタンス
タッチイベント
onFling
package com.test; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.GestureDetector.SimpleOnGestureListener; public class Test01Activity extends Activity { private GestureDetector myGestureDetector; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myGestureDetector = new GestureDetector(new MyGestureListener()); } @Override public boolean onTouchEvent(MotionEvent event) { if (myGestureDetector.onTouchEvent(event)) return true; else return false; } private class MyGestureListener extends SimpleOnGestureListener { @Override public boolean onFling( MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { //float dX = e2.getX() - e1.getX(); //float dY = e2.getY() - e1.getY(); //Log.d("タグ", String.valueOf( dX ) ); Intent subactivity = new Intent(Test01Activity.this, com.test.SubActivity.class); startActivity(subactivity); return false; } } }
0 件のコメント:
コメントを投稿