Android UI Learning Gallery

Source: Internet
Author: User

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

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.