The layout file is as follows:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <ViewFlipper android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="fill_parent" />
- <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"
- android:background="@drawable/bottom_bg" android:layout_alignParentBottom="true" android:gravity="center_vertical" style="@android:style/ButtonBar">
- <ImageButton android:id="@+id/searchBtn" android:src="@drawable/search_on" android:background="#00000000" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" />
- <ImageButton android:id="@+id/historyBtn" android:src="@drawable/history" android:background="#00000000" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" />
- <ImageButton android:id="@+id/starredBtn" android:src="@drawable/starred" android:background="#00000000" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" />
- </LinearLayout>
- </RelativeLayout>
The Code is as follows:
- Import Android. App. activity;
- Import Android. content. intent;
- Import Android. OS. Bundle;
- Import Android. View. layoutinflater;
- Import Android. View. view;
- Import Android. View. View. onclicklistener;
- Import Android. widget. imagebutton;
- Import Android. widget. viewflipper;
- Public Class search extends activity {
- Private imagebutton searchbtn;
- Private imagebutton historybtn;
- Private imagebutton starredbtn;
- // Convert multiple views through viewflipper
- Private viewflipper Flipper;
- @ Override
- Public void oncreate (bundle savedinstancestate ){
- Super. oncreate (savedinstancestate );
- Setcontentview (R. layout. Main );
- Findviews ();
- Bindlistener ();
- }
- Public void findviews (){
- Searchbtn = (imagebutton) findviewbyid (R. Id. searchbtn );
- Historybtn = (imagebutton) findviewbyid (R. Id. historybtn );
- Starredbtn = (imagebutton) findviewbyid (R. Id. starredbtn );
-
- Flipper = (viewflipper) findviewbyid (R. Id. Flipper );
-
- Layoutinflater = This. getlayoutinflater ();
- View search = layoutinflater. Inflate (R. layout. Search, null );
- View history = layoutinflater. Inflate (R. layout. History, null );
- View starred = layoutinflater. Inflate (R. layout. starred, null );
- // Add three views to viewflipper
- Flipper. addview (search, 0 );
- Flipper. addview (history, 1 );
- Flipper. addview (starred, 2 );
- // Set to display the first view
- Flipper. setdisplayedchild (0 );
- }
- Public void bindlistener (){
- Searchbtn. setonclicklistener (New onclicklistener (){
- // Click the first button and set the view to 0.
- @ Override
- Public void onclick (view v ){
- Searchbtn. setimageresource (R. drawable. search_on );
- Historybtn. setimageresource (R. drawable. History );
- Starredbtn. setimageresource (R. drawable. starred );
- Flipper. setdisplayedchild (0 );
- }
- });
- Historybtn. setonclicklistener (New onclicklistener (){
-
// Click the second button and set view to 1
- @ Override
- Public void onclick (view v ){
- Searchbtn. setimageresource (R. drawable. Search );
- Historybtn. setimageresource (R. drawable. history_on );
- Starredbtn. setimageresource (R. drawable. starred );
- Flipper. setdisplayedchild (1 );
- }
- });
- Starredbtn. setonclicklistener (New onclicklistener (){
// Click the third button and set view to 2
- @ Override
- Public void onclick (view v ){
- Searchbtn. setimageresource (R. drawable. Search );
- Historybtn. setimageresource (R. drawable. History );
- Starredbtn. setimageresource (R. drawable. starred_on );
- Flipper. setdisplayedchild (2 );
- }
- });
- }
- }
Program: