1. Achieving results
2. Implementing the Code
<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <Imageswitcher Android:id= "@+id/is_switcher"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_alignparentleft= "true"Android:layout_alignparenttop= "true"/> <Gallery Android:id= "@+id/gallery"Android:layout_width= "Match_parent"Android:layout_height= "60DP"Android:background= "#55000000"Android:layout_alignparentbottom= "true"Android:layout_alignparentleft= "true"android:gravity= "Center_vertical"android:spacing= "16DP"/></relativelayout>
Layout
Public classMainactivityextendsActivityImplementsOnitemselectedlistener, viewfactory {/*** Imageswitcher Control*/ PrivateImageswitcher Is_switcher; /*** Gallery Control*/ PrivateGallery Galley; /*** Arrays used by small graphs*/ Privateinteger[] Mthumbids ={r.drawable.pic, R.drawable.pic2, R.DRAWABLE.PIC3, R.drawable.pic4, r.drawable.pic5}; /*** Arrays used by large graphs*/ Privateinteger[] Mimageids ={r.drawable.ic_launcher, R.drawable.pic2, R.drawable.ic_launcher, R.drawable.pic2, r.drawable . Ic_launcher}; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); /*** Use untitled style*/requestwindowfeature (Window.feature_no_title); /*** Set the displayed layout file*/Setcontentview (R.layout.activity_main); /*** Instantiate the Imageswitcher control and associate it with it*/Is_switcher=(Imageswitcher) Findviewbyid (R.id.is_switcher); /*** Refer to the following Makeview because the Viewfactory interface is implemented*/Is_switcher.setfactory ( This); //Set the default style for entering animations and going out animations using the systemIs_switcher.setinanimation (Animationutils.loadanimation ( This, Android. r.anim.fade_in)); Is_switcher.setoutanimation (Animationutils.loadanimation ( This, Android. R.anim.fade_out)); /*** Instantiate a gallery control and bind it*/Galley=(Gallery) Findviewbyid (r.id.gallery); //to set an adapter for a gallery objectGalley.setadapter (NewImageadapter ( This)); /*** Set the Listener event when the Gallery object option is selected*/Galley.setonitemselectedlistener ( This); } @Override PublicView Makeview () {ImageView I=NewImageView ( This); I.setbackgroundcolor (0xff000000); I.setscaletype (ImageView.ScaleType.FIT_CENTER); I.setlayoutparams (Newimageswitcher.layoutparams (layoutparams.match_parent, layoutparams.match_parent)); returni; } Public classImageadapterextendsBaseadapter { PublicImageadapter (Context c) {Mcontext=C; } Public intGetCount () {returnmthumbids.length; } PublicObject GetItem (intposition) { returnposition; } Public LongGetitemid (intposition) { returnposition; } PublicView GetView (intposition, View Convertview, ViewGroup parent) {ImageView I=NewImageView (Mcontext); I.setimageresource (Mthumbids[position]); I.setadjustviewbounds (true); I.setlayoutparams (Newgallery.layoutparams (layoutparams.wrap_content, layoutparams.wrap_content)); I.setbackgroundresource (R.drawable.ic_launcher); returni; } PrivateContext Mcontext; } @Override Public voidOnitemselected (adapterview<?> Parent, view view,intposition,LongID) {is_switcher.setimageresource (mimageids[position]); } @Override Public voidOnnothingselected (adapterview<?>parent) { }}
Java
3. Picture
Android-Imageswitch and gallery mixed use