Android 25th Lesson--imageswitcher

Source: Internet
Author: User

Use Imageswitcher to change images for gradient effects

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"android:gravity= "Center_horizontal">    <GridViewAndroid:id= "@+id/gridview"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:horizontalspacing= "2pt"android:verticalspacing= "2pt"android:gravity= "Center"Android:numcolumns= "4" >    </GridView>    <ImageswitcherAndroid:id= "@+id/imageswitcher1"Android:layout_width= "300DP"Android:layout_height= "300DP"android:layout_gravity= "Center_horizontal"android:inanimation= "@android: anim/fade_in"android:outanimation= "@android: Anim/fade_out"         >    </Imageswitcher> </LinearLayout>
 PackageCom.example.imageswitcher;Importjava.util.ArrayList;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Map;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.ViewGroup.LayoutParams;ImportAndroid.widget.AdapterView;ImportAndroid.widget.AdapterView.OnItemClickListener;ImportAndroid.widget.AdapterView.OnItemSelectedListener;ImportAndroid.widget.GridView;ImportAndroid.widget.ImageSwitcher;ImportAndroid.widget.ImageView;ImportAndroid.widget.SimpleAdapter;Importandroid.widget.ViewSwitcher.ViewFactory; Public classMainactivityextendsActivity {int[] imageids=New int[]{r.drawable.bomb5,r.drawable.bomb6,r.drawable.bomb7,r.drawable.bomb8, R.DRAWABLE.BOMB9,R.DRAWABLE.BOMB10,    R.DRAWABLE.BOMB11,R.DRAWABLE.BOMB12, R.DRAWABLE.BOMB13,R.DRAWABLE.BOMB14,R.DRAWABLE.BOMB15,R.DRAWABLE.BOMB16};    Imageswitcher switcher; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); List<Map<String,Object>> listitems=NewArraylist<map<string,object>>();  for(inti=0;i<imageids.length;i++) {Map<String,Object> listitem=NewHashmap<string,object>(); Listitem.put ("Image", Imageids[i]);        Listitems.add (ListItem); } Switcher=(Imageswitcher) Findviewbyid (r.id.imageswitcher1); Switcher.setfactory (Newviewfactory () {@Override PublicView Makeview () {ImageView ImageView=NewImageView (mainactivity. This);                Imageview.setscaletype (ImageView.ScaleType.FIT_CENTER); Imageview.setlayoutparams (NewImageswitcher.layoutparams (layoutparams.wrap_content,layoutparams.wrap_content)); returnImageView;        }                    }); Simpleadapter Simpleadapter=NewSimpleadapter ( This, ListItems, R.layout.cell,Newstring[]{"Image"},New int[]{r.id.image1}]; GridView Grid=(GridView) Findviewbyid (R.id.gridview);    Grid.setadapter (Simpleadapter); Grid.setonitemselectedlistener (NewOnitemselectedlistener () {@Override Public voidOnitemselected (adapterview<?>Parent, view view,intPositionLongID) {switcher.setimageresource (imageids[position]); } @Override Public voidOnnothingselected (adapterview<?>parent)    {        }            }); Grid.setonitemclicklistener (NewOnitemclicklistener () {@Override Public voidOnitemclick (adapterview<?> Parent, view view,intposition,LongID) {switcher.setimageresource (imageids[position]);    }}); }}

Android 25th Lesson--imageswitcher

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.