title: Android: swipe screen to open another activity?
body: <p>i'm a n00b programmer and need a lot of help.</p>
  
  <p>Just for tutorial purpose, I want to make simple flora &amp; fauna (plant &amp; animal) encyclopedia</p>
  
  <p>I want to make my home screen <strong>drag-able just like the Android's home screen</strong>. Swipe right to open Plant page and swipe left to open Animal page.
  I don't know how to make the <strong>transition effect</strong>. So we can drag it halfway to peek what's in next page and just drag back to cancel it</p>
  
  <p>Can you guys share a link to make the drag-able screen?</p>
  
  <p>Thanks before</p>
  
  <p><strong>[Edit]</strong></p>
  
  <p>@Agarwal
  I tried the code from your Link2 and it's not working </p>
  
  <p>I try to test whether the gesture detected or not by putting Toast inside the inner class but the Toast isn't shown. The Link1 is basically the same though.</p>
  
  <p>and from the looks of the code, I think it can't make my screen drag-able like in Android's home screen</p>
  
  <p>my code:</p>
  
  <pre><code>public class Home extends Activity implements OnClickListener {
      private GestureDetector gestureDetector;
      View.OnTouchListener gestureListener;
      ImageButton flora, fauna;
      Intent go;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      initialize();
  
      gestureDetector = new GestureDetector(new SwipeGestureDetector());
      gestureListener = new View.OnTouchListener() {
          public boolean onTouch(View v, MotionEvent event) {
              return gestureDetector.onTouchEvent(event);
          }
      };
  }
  
  private void initialize() {
      //find view by id to image button
      //set onClickListener to image button
  }
  
  public void onClick(View v) {
      //normal switch and case for each button
  
  }
  
  private void onLeftSwipe() {
      Toast t = Toast.makeText(Home.this, "Left swipe", Toast.LENGTH_LONG);
      t.show();
      go = new Intent("test.apps.FLORA");
      startActivity(go);
  }
  
  private void onRightSwipe() {
      Toast t = Toast.makeText(Home.this, "Right swipe", Toast.LENGTH_LONG);
      t.show();
      go = new Intent("test.apps.FAUNA");
      startActivity(go);
  }
  
  private class SwipeGestureDetector extends SimpleOnGestureListener {
      private static final int SWIPE_MIN_DISTANCE = 50;
      private static final int SWIPE_MAX_OFF_PATH = 200;
      private static final int SWIPE_THRESHOLD_VELOCITY = 200;
  
      @Override
      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
              float velocityY) {
          try {
              Toast t = Toast.makeText(Home.this, "Gesture detected", Toast.LENGTH_SHORT);
              t.show();
              float diffAbs = Math.abs(e1.getY() - e2.getY());
              float diff = e1.getX() - e2.getX();
  
              if (diffAbs &gt; SWIPE_MAX_OFF_PATH)
                  return false;
  
              // Left swipe
              if (diff &gt; SWIPE_MIN_DISTANCE
                      &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
                  Home.this.onLeftSwipe();
              } 
              // Right swipe
              else if (-diff &gt; SWIPE_MIN_DISTANCE
                      &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
                  Home.this.onRightSwipe();
              }
          } catch (Exception e) {
              Log.e("Home", "Error on gestures");
          }
          return false;
      }
  
  }
  }
  </code></pre>