Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make ViewFlipper in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 144
    Comment on it

    In the below example i have created ViewFlipper function. Here I have used ViewFlipper attribute in main.xml layout. ViewFlipper can be used to slide views in and out on the users current view port. I have used two buttons When we will click next button next TextView will open and when we will click prev button it will show previous textview . See the below example it will clearly described you how to make ViewFlipper.

    Step(1)-MainActivity-

    public class MainActivity extends Activity {
    
        ViewFlipper viewFlipper;
        Button Next, Previous;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            viewFlipper = (ViewFlipper) findViewById(R.id.ViewFlipper01);
    
            Next = (Button) findViewById(R.id.Next);
            Previous = (Button) findViewById(R.id.Previous);
    
            Next.setOnClickListener(new View.OnClickListener() {
    
                public void onClick(View v) {
                    // TODO Auto-generated method stub
    
                    viewFlipper.showNext();
                }
            });
    
            Previous.setOnClickListener(new View.OnClickListener() {
    
                public void onClick(View v) {
                    // TODO Auto-generated method stub
    
                    viewFlipper.showPrevious();
                }
            });
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.menu_main, menu);
            return true;
        }
    }
    

    Step(2)-activity.main.xml-

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <RelativeLayout
            android:id="@+id/RelativeLayout02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
    
            <ViewFlipper
                android:id="@+id/ViewFlipper01"
                android:layout_width="fill_parent"
                android:layout_height="400dp" >
    
                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="#4B0082" >
    
                    <TextView
                        android:id="@+id/TextView01"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="#FFFFFF"
                        android:textSize="50dp"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="100dp"
                        android:text="Evon" >
                    </TextView>
    
                </RelativeLayout>
    
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#7CFC00"
                    android:orientation="vertical" >
    
                    <TextView
                        android:id="@+id/TextView02"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="#000000"
                        android:textSize="50dp"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="100dp"
                        android:text="HCL" >
                    </TextView>
    
                </RelativeLayout>
    
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#1E90FF"
                    android:orientation="vertical" >
    
                    <TextView
                        android:id="@+id/TextView03"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="#FFFFFF"
                        android:textSize="50dp"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="100dp"
                        android:text="Microsoft" >
                    </TextView>
    
                </RelativeLayout>
    
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#FFFF00"
                    android:orientation="vertical" >
    
                    <TextView
                        android:id="@+id/TextView04"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="#000000"
                        android:textSize="50dp"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="100dp"
                        android:text="Ericsson" >
                    </TextView>
    
                </RelativeLayout>
    
            </ViewFlipper>
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/RelativeLayout03"
            android:layout_below="@+id/RelativeLayout02"
            android:background="#000000"
            android:layout_width="fill_parent"
            android:layout_height="match_parent">
    
            <Button
                android:id="@+id/Previous"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="20dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Previous" >
            </Button>
    
            <Button
                android:id="@+id/Next"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_marginBottom="5dp"
                android:layout_marginRight="20dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Next" >
            </Button>
    
        </RelativeLayout>
    
    </LinearLayout>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: