Messy Android gallery image display application

Source: Internet
Author: User

What is gallery used? Gallery Chinese means galleries and galleries. In fact, gallery is mainly used to display images in Android, which can provide dynamic and beautiful animation effects for image display.

The pictures in my example are all made at will. It's really ugly. I don't need to map it, but the effect is still realized. Here we will mainly use technology ...... ⊙ B Khan

Gallery. XML code:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout <br/> xmns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent"> </P> <p> <gallery <br/> Android: id = "@ + ID/Gallery" <br/> Android: gravity = "center" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> </gallery> <br/> <textview <br/> Android: id = "@ + ID/textview_gallery" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "image Introduction" <br/> </P> <p> </linearlayout> <br/>

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. widget. baseadapter; <br/> Import android. widget. gallery; <br/> Import android. widget. imageview; <br/> Import android. widget. spinneradapter; <br/>/** <br/> * @ description test the usage of Android gallery <br/> * @ author chenzheng_java <br/> */< br/> public class galleryactivity extends activity {</P> <p> @ override <br/> protected void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. gallery); <br/> // gallery is essentially a display control. Don't think about it too well. <br/> gallery = (Gallery) findviewbyid (R. id. gallery); <br/>/* set the data source for gallery <br/> * setadapter (spinneradapter adapter ); it requires us to provide a parameter of the spinneradapter type <br/> * Why do we provide parameters of the baseadapter type here? It is very simple, baseadapter inherits the spinneradapter <br/> **/<br/> Gallery. setadapter (New imageadapter (this )); </P> <p >}</P> <p>/** <br/> * @ description implement your own adapter <br/> * @ author chenzheng_java <br/> * <br/> */<br/> private class imageadapter extends baseadapter {<br/> private context; <br/> // indicates the index array of the image. <br/> private int [] images = new int [] {<br/> r. drawable. icon, <br/> r. drawable. baidu, <br/> r. drawable. excel <br/>}; </P> <p> Public imageadapter (context) {<br/> This. context = context; </P> <p >}</P> <p> @ override <br/> Public int getcount () {<br/> return images. length; <br/>}</P> <p> @ override <br/> Public object getitem (INT position) {<br/> return position; <br/>}</P> <p> @ override <br/> Public long getitemid (INT position) {<br/> return position; <br/>}< br/>/** <br/> * view getview (INT position, view convertview, viewgroup parent) <br/> * position indicates the position of the current view in callery, starting from 0 <br/> * convertview current view <br/> * parent container of the current view of the parent <br/> */<br/> @ override <br/> Public View getview (INT position, view convertview, viewgroup parent) {<br/> If (convertview = NULL) {<br/> convertview = new imageview (context ); <br/>}</P> <p> convertview. setbackgroundresource (images [position]); <br/> (imageview) convertview ). setscaletype (imageview. scaletype. fit_center); <br/> convertview. setlayoutparams (new gallery. layoutparams (120,120); <br/> return convertview; <br/>}</P> <p >}< br/>

-----------------------------------------------------------------------------

We can see that the gallery usage is very simple. All we need to do is declare it in the layout file and set the data source for it in the code.

 

Related Article

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.