Finally:
When we switch the image in the bottom gallery, the large image above will automatically switch and there will be an animation effect when switching. It's a very simple program and more functions need to be improved!
Activity Code:
Package cn.com. chenzheng_java; </P> <p> Import android. app. activity; <br/> Import android. content. context; <br/> Import android. OS. bundle; <br/> Import android. view. view; <br/> Import android. view. viewgroup; <br/> Import android. view. window; <br/> Import android. view. animation. animationutils; <br/> Import android. widget. adapterview; <br/> Import android. widget. baseadapter; <br/> Import android. widget. gallery; <Br/> Import android. widget. imageswitcher; <br/> Import android. widget. imageview; <br/> Import android. widget. toast; <br/> Import android. widget. adapterview. onitemselectedlistener; <br/> Import android. widget. imageview. scaletype; <br/> Import android. widget. viewswitcher. viewfactory; <br/>/** <br/> * @ description shows a small image <br/> * @ author chenzheng_java <br/> * @ since 2011/3/17 <br/> * <br/> */<br/> pub LIC class galleryactivity extends activity implements onitemselectedlistener {</P> <p> int [] imagesid = new int [] {R. drawable. a1, R. drawable. a2, R. drawable. a3, <br/> r. drawable. a4 </P> <p >}; <br/> int Index = R. drawable. a1; <br/> imageswitcher; </P> <p> @ override <br/> protected void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/>/** <br/> * If the window does not have a title bar, you must Set tcontentview before <br/> */<br/> requestwindowfeature (window. feature_no_title); <br/> setcontentview (R. layout. gallery); </P> <p> gallery = (Gallery) findviewbyid (R. id. gallery1); <br/> Gallery. setonitemselectedlistener (this); </P> <p> imageswitcher = (imageswitcher) findviewbyid (R. id. imageswitcher); <br/> imageswitcher. setvisibility (view. visible); </P> <p>/*** <br/> * setinanimation allows you to set a fade-in animation <br/> * se Toutanimation allows you to set a fade-out animation <br/> */<br/> imageswitcher. setinanimation (animationutils. loadanimation (<br/> getapplicationcontext (), android. r. anim. fade_in); <br/> imageswitcher. setoutanimation (animationutils. loadanimation (<br/> getapplicationcontext (), android. r. anim. fade_out); </P> <p> imageswitcher. setfactory (New viewfactory () {<br/>/** <br/> * create a new image and place it on imageswitcher. You can use it to set the background. <Br/> * generally, it is called only once during creation. It is equivalent to creating a background image for animation. <Br/> * This method can also be replaced by setview <br/> */<br/> @ override <br/> Public View makeview () {<br/> imageview = new imageview (galleryactivity. this); <br/> // set the interception mode <br/> imageview. setscaletype (scaletype. center_inside); <br/> imageview. setbackgroundresource (R. drawable. ground); <br/> toast. maketext (getapplicationcontext (), "executed once", <br/> toast. length_short ). show (); <br/> return imageview; <br/>}< br/>}); </P> <P> Gallery. setvisibility (view. visible); <br/> Gallery. setadapter (New imageadapter (this); </P> <p >}</P> <p> class imageadapter extends baseadapter {<br/> private context context2; </P> <p> Public imageadapter (context) {<br/> context2 = context; <br/>}</P> <p> @ override <br/> Public int getcount () {<br/> return imagesid. length; <br/>}</P> <p> @ override <br/> Public object getitem (INT position) {<br/> retu Rn imagesid [position]; <br/>}</P> <p> @ override <br/> Public long getitemid (INT position) {<br/> return position; <br/>}</P> <p> @ override <br/> Public View getview (INT position, view image2, viewgroup parent) {<br/> imageview image = new imageview (context2); <br/> image. setbackgroundresource (imagesid [position]); <br/>/** <br/> * setscaletype () allows you to set the editing mode when the image size and container size do not match. <br/> * scaletype. center_inside means, Scale down or expand according to the original proportion of the image until any one of the long or wide ends to the container <br/> */<br/> image. setscaletype (scaletype. center_inside); </P> <p> return image; <br/>}</P> <p >}< br/>/** <br/> * When the gallery image changes, synchronize imageswitcher changes <br/> */<br/> @ override <br/> Public void onitemselected (adapterview <?> Parent, view, int position, <br/> long ID) {<br/> imageswitcher. setimageresource (imagesid [position]); </P> <p >}</P> <p> @ override <br/> Public void onnothingselected (adapterview <?> Parent) {</P> <p >}< br/>
Gallery. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout <br/> xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical" <br/> Android: gravity = "center_horizontal" <br/> </P> <p> <imageswitcher <br/> Android: Id = "@ + ID/imageswitcher" <br/> Android: layout_height = "350dp" <br/> Android: layout_width = "fill_parent" <br/> </imageswitcher> </P> <p> <gallery Android: id = "@ + ID/gallery1" <br/> Android: gravity = "center" <br/> Android: layout_width = "70dp" <br/> Android: layout_height = "100dp"> </gallery> <br/> </linearlayout> <br/>