package com.android_examples.viewanimator_android_examplescom;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ViewAnimator;

public class MainActivity extends AppCompatActivity {

    ViewAnimator viewAnimator ;
    Button buttonN , buttonP ;
    Animation animationIn, animationOut ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        viewAnimator = (ViewAnimator)findViewById(R.id.viewAnimator1);
        buttonN = (Button)findViewById(R.id.button2);
        buttonP = (Button)findViewById(R.id.button);

        animationIn =  AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_in_left);
        animationOut = AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_out_right);

        viewAnimator.setInAnimation(animationIn);
        viewAnimator.setOutAnimation(animationOut);

        buttonP.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                viewAnimator.showPrevious();

            }
        });


        buttonN.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                viewAnimator.showNext();

            }
        });

    }
}
