The role of Viewswitcher is simply to show animations when converting between two views
Its two subclasses should be familiar,
Imageswitcher: Increase animation effect when converting pictures;
Textswitcher: Increase animation effect when converting text;
Layout:
<?XML version= "1.0" encoding= "Utf-8"?> <Viewswitcher xmlns:android= "Http://schemas.android.com/apk/res/android"Android:id= "@+id/view_switcher"Android:layout_width= "Match_parent"android:inanimation= "@android: Anim/slide_in_left"android:outanimation= "@android: Anim/slide_out_right"Android:layout_height= "Match_parent" > <!--First View - <RelativelayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <ButtonAndroid:id= "@+id/ne"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centervertical= "true"Android:text= "Next"/> </Relativelayout> <!--a second view - <RelativelayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <ButtonAndroid:id= "@+id/up"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centervertical= "true"Android:text= "Previous"/> <ImageViewAndroid:id= "@+id/image"Android:layout_torightof= "@id/up"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centervertical= "true"android:src= "@drawable/ic_launcher"/> </Relativelayout></Viewswitcher>
Switching of the interface
Public classViewswitcheractextendsactivity{PrivateViewswitcher switcher; PrivateButton Upper,next; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.view_switcher); Switcher=(Viewswitcher) Findviewbyid (R.id.view_switcher); Upper=(Button) Findviewbyid (r.id.up); Next=(Button) Findviewbyid (r.id.ne); // switch to the first view switcher.setdisplayedchild (0); Upper.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {switcher.showprevious (); } }); Next.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {switcher.shownext (); } }); }}
Layout:
Android Animation (5) Viewswitcher