Slide In and Slide Out animation for a layout

Use this xml in res/anim/

leftright.xml
This is for left to right animation:

  <set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
    <translate android:fromXDelta="-100%" android:toXDelta="0%"
      android:fromYDelta="0%" android:toYDelta="0%"
     android:duration="700"/>
   </set>

use this in your java code

Handler handler = new Handler();
Runnable runnable = new Runnable(){
{
   public void run()
 {
   item[i].setInAnimation(AnimationUtils.loadAnimation(this,R.anim.leftright.xml));
   i=i+1;
   handler.postDelayed(this,5000);
 }
};handler.postDelayed(runnable,5000);

If your layouts are having identical content, create two layouts inside a view flipper. Load first view with data and show it. When user clicks next or previous, load next view with data and keep a flag to show that 2nd view is now visible and show it with animation.

Now onwards load the appropriate views with data based on the flag values and call shownext().

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mainFlipper = (ViewFlipper) findViewById(R.id.flipper);
    firstLayout = (LinearLayout) findViewById(R.id.layout1);
    secondLayout = (LinearLayout) findViewById(R.id.layout2);


    findViewById(R.id.btnPrevious).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            showPrevious();
        }
    });

    findViewById(R.id.btnNext).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            showNext();
        }
    });

}

private void showNext() {
    mainFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_left));
    mainFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_right));
    flip();
}

private void showPrevious() {
    mainFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_right));
    mainFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_left));
    flip();
}

private void flip() {
    if(isFirstVisible) {
        isFirstVisible = false;
        secondLayout.removeAllViews();
        secondLayout.addView(getTextView("Second"));
    } else {
        isFirstVisible = true;
        firstLayout.removeAllViews();
        firstLayout.addView(getTextView("First"));
    }
    mainFlipper.showNext();
}

private TextView getTextView(String txt) {
    TextView txtView = new TextView(this);
    txtView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    txtView.setText(txt);
    return txtView;
}