Flipper Example
In ViewFlipper, which we display a ViewFlipper with three views first is ImageView, second is a layout in which we have a two TextView’s and third is also a layout in which we have two Button’s.
actvity_main.xml
This xml shows the code for displaying a Button and a ViewFlipper with three child views.
MainActivity.java
This activity shows the code for initiate the ViewFlipper and Button.
package com.example.icowboysradio.myapplication; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ViewFlipper; public class MainActivity extends AppCompatActivity{ ViewFlipper viewFlipper; Button btnNext; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnNext = (Button) findViewById(R.id.btnNext); viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper); Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right); viewFlipper.setInAnimation(in); viewFlipper.setOutAnimation(out); btnNext.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub viewFlipper.showNext(); } }); } }
Leave A Comment