title: How to slide the tab contents (of TabActivity) with finger movement like in "Home", "News & Weather app"?
body: <p>I have a tab activity with three tabs. I need the sliding animation with the finger movement that does like in Home or "News &amp; Weather" app. With the help of documentation and forum, I could manage to animate the tab contents in some extent but not like in those mention above.</p>
  
  <p>So, would you please help me to solve this issue?</p>
  
  <p>Here is my code:</p>
  
  <p>MyTabActivity.java</p>
  
  <pre><code>public class MyTabActivity extends TabActivity {
  
      int current_tab;
      TabHost tabHost;
  
      private static final int SWIPE_MIN_DISTANCE = 120;
      private static final int SWIPE_MAX_OFF_PATH = 250;
      private static final int SWIPE_THRESHOLD_VELOCITY = 200;
  
      private GestureDetector gestureDetector;
      private Animation slideLeftIn;
      private Animation slideLeftOut;
      private Animation slideRightIn;
      private Animation slideRightOut;
      private ViewFlipper viewFlipper;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.mains);
  
          viewFlipper = (ViewFlipper) findViewById(R.id.flipper);
  
          slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
          slideLeftOut = AnimationUtils
                  .loadAnimation(this, R.anim.slide_left_out);
          slideRightIn = AnimationUtils
                  .loadAnimation(this, R.anim.slide_right_in);
          slideRightOut = AnimationUtils.loadAnimation(this,
                  R.anim.slide_right_out);
  
          gestureDetector = new GestureDetector(new MyGestureDetector());
  
          Resources res = getResources(); 
          tabHost = getTabHost();
          TabHost.TabSpec spec;
          Intent intent;
  
          intent = new Intent().setClass(this, FirstTabContentAcitivity.class);
          spec = tabHost.newTabSpec("first").setIndicator("First",
                  res.getDrawable(R.drawable.first)).setContent(intent);
          tabHost.addTab(spec);
  
          intent = new Intent().setClass(this, SecondTabContentActivity.class);
          spec = tabHost.newTabSpec("second").setIndicator("Second",
                  res.getDrawable(R.drawable.second)).setContent(intent);
          tabHost.addTab(spec);
  
          intent = new Intent().setClass(this, ThirdTabContentAcitivity.class);
          spec = tabHost.newTabSpec("third").setIndicator("Third",
                  res.getDrawable(R.drawable.third)).setContent(intent);
          tabHost.addTab(spec);
  
  
          tabHost.setCurrentTab(0);
  
      }
  
  
      class MyGestureDetector extends SimpleOnGestureListener {
          @Override
          public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                  float velocityY) {
              Log.d("Gesture", "Detected inside class.");
              try {
                  if (Math.abs(e1.getY() - e2.getY()) &gt; SWIPE_MAX_OFF_PATH)
                      return false;
  
                  if (e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE
                          &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
  
                          viewFlipper.setInAnimation(slideLeftIn);
                          viewFlipper.setOutAnimation(slideLeftOut);
                          viewFlipper.showNext();                     
  
                          //overridePendingTransition(R.anim.slide_left_in, R.anim.slide_left_out);
                      }
                  } else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE
                          &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
  
  
                          viewFlipper.setInAnimation(slideRightIn);
                          viewFlipper.setOutAnimation(slideRightOut);
                          viewFlipper.showPrevious();                     
                      }
                  }
              } catch (Exception ex) {
                  Log.d("onFling", ex.getMessage());
              }
              return false;
          }
      }
  
      /*
       * @Override public boolean onTouchEvent(MotionEvent event) { if
       * (gestureDetector.onTouchEvent(event)) { Log.d("onTouchEvent",
       * "screen touched"); return true; } else { return false; } }
       */
  
      @Override
      public boolean dispatchTouchEvent(MotionEvent event) {
          super.dispatchTouchEvent(event);
          return gestureDetector.onTouchEvent(event);
      }   
  }
  </code></pre>
  
  <p>main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
      &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@android:id/tabhost" android:layout_width="fill_parent"
          android:layout_height="fill_parent" android:layout_weight="1"&gt;
          &lt;LinearLayout android:orientation="vertical"
              android:layout_width="fill_parent" android:layout_height="fill_parent"&gt;
              &lt;TabWidget android:id="@android:id/tabs"
                  android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt;
              &lt;ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
                  android:id="@+id/flipper" android:layout_width="fill_parent"
                  android:layout_height="fill_parent"&gt;
                  &lt;FrameLayout android:id="@android:id/tabcontent"
                      android:layout_width="fill_parent" android:layout_height="fill_parent"&gt;
                  &lt;/FrameLayout&gt;
              &lt;/ViewFlipper&gt;
          &lt;/LinearLayout&gt;
      &lt;/TabHost&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>slide_left_in.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;set xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;translate android:fromXDelta="50%p" android:toXDelta="0"
          android:duration="800" /&gt;
  &lt;/set&gt;
  </code></pre>
  
  <p>slide_left_out.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;set xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;translate android:fromXDelta="0" android:toXDelta="-50%p"
          android:duration="800" /&gt;
  &lt;/set&gt;
  </code></pre>
  
  <p>slide_right_in.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;set xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;translate android:fromXDelta="-50%p" android:toXDelta="0"
          android:duration="800" /&gt;
  &lt;/set&gt;
  </code></pre>
  
  <p>slide_right_out.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;set xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;translate android:fromXDelta="0" android:toXDelta="50%p"
          android:duration="800" /&gt;
  &lt;/set&gt;
  </code></pre>