1. Introduction
It is the gallery component, which can slide the image to produce the slide effect!
2.
3. xml file
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Gallery android:layout_width="fill_parent" android:id="@+id/gallery1" android:layout_height="fill_parent" android:spacing="16dp"></Gallery></RelativeLayout>
4. Java code
Package Wei. ye. g1; import android. app. activity; import android. content. context; import android. OS. bundle; import android. view. view; import android. view. viewgroup; import android. view. viewgroup. layoutparams; import android. widget. baseadapter; import android. widget. gallery; import android. widget. imageview; public class Huadong extends activity {Private Static int [] images = {R. drawable. baos, R. drawable. caoc, R. drawable. chenyj, R. drawable. chenyy, R. drawable. gouj, R. drawable. guany, R. drawable. hanx, R. drawable. LP, R. drawable. liub, R. drawable. qinq, R. drawable. tiemz, R. drawable. wus, R. drawable. xiangy, R. drawable. yuef, R. drawable. zhaoky, R. drawable. zhugl, R. drawable. xis, R. drawable. yingz}; gallery Gallery; @ override protected void oncreate (bundle savedinstancestate) {// todo auto-generated method stub super. oncreate (savedinstancestate); setcontentview (R. layout. huadong); settitle ("only using gallery effect"); gallery = (Gallery) findviewbyid (R. id. gallery1); Gallery. setadapter (New imageadapter (this); Gallery. setselection (images. length/2);} private class imageadapter extends baseadapter {private context; Public imageadapter (context) {This. context = context;} // return images. lenght (), returns integer here. max_value // to make the image display public int getcount () {return integer cyclically. max_value;} public object getitem (INT position) {return NULL;} public long getitemid (INT position) {return 0;} public view getview (INT position, view convertview, viewgroup parent) {imageview IV = new imageview (context); // you can specify the image IV to be displayed. setimageresource (images [position % images. length]); // set the height and width of the imageview IV. setlayoutparams (new gallery. layoutparams (layoutparams. fill_parent, layoutparams. fill_parent); IV. setadjustviewbounds (true); Return IV ;}}}