In life everyone will browse the pictures on the phone, then swipe from left to right with your fingers. In fact, this effect is achieved with the help of gallery.
The next simple example introduces the use of gallery:
public class Galleryactivty extends Activity {private static Gallery mgallery;private int[] images = {R.DRAWABLE.A, R.draw ABLE.B,R.DRAWABLE.C, R.DRAWABLE.D,R.DRAWABLE.E, r.drawable.f,r.drawable.h}; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_gallery) MGallery = (gallery) Findviewbyid (r.id.gallery); Mgallery.setadapter (new MyAdapter (this) ); mgallery.setspacing (10);} Class Myadapter extends Baseadapter{private context context;public Myadapter (context context) {This.context = context;} @Overridepublic int GetCount () {//Gets the total number of picture resources return images.length;} @Overridepublic Object getItem (int position) {//Get the picture's current position return position;} @Overridepublic long Getitemid (int position) {//Get picture of current position Idreturn images[position];} @Overridepublic view GetView (int position, view Convertview, ViewGroup parent) {//Get current picture resource ImageView View = new ImageView ( This.context); View.setimageresource (Images[position]); View.setadjustviewbounds (true);//Set the size of the picture View.setlayoutparams (new Gallery.layoutparams (300, 300));// View.setpadding (all, ten, ten); return view;}}}
The layout file is simple:
<gallery android:id= "@+id/gallery" android:layout_width= "fill_parent" android:layout_height= " Wrap_content " android:layout_centervertical=" true " />
The results are as follows:
Summary: General gallery and Imageswitcher are used together. This will have a more flattering effect.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android UI Learning Gallery