Android-Imageswitch and gallery mixed use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.