Android user interface-widget-gallery view Gallery

Source: Internet
Author: User

The gallery control of Android is a Good Graph Display Control, which greatly reduces developers' development of the Image view function and provides a more elegant effect.

 

/Chapter04_ui_gallery01/src/COM/Amaker/test/mainactivity. Java

Code

  Package  Com. Amaker. test;

Import Android. App. activity;
Import Android. content. context;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. viewgroup;
Import Android. widget. baseadapter;
Import Android. widget. Gallery;
Import Android. widget. imageview;

Public Class Mainactivity Extends Activity {
/** Called when the activity is first created. */
@ Override
// Called at creation
Public Void Oncreate (bundle savedinstancestate ){
Super . Oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Gallery g = (Gallery) findviewbyid (R. Id. gallery01 );

G. setadapter ( New Myadapter ( This ));
}

Class Myadapter Extends Baseadapter {
Context context;
Myadapter (context ){
This . Context = Context;
}
Private Integer [] IMGs = {
R. drawable. gallery_photo_1,
R. drawable. gallery_photo_2,
R. drawable. gallery_photo_3,
R. drawable. gallery_photo_4,
R. drawable. gallery_photo_5,
R. drawable. gallery_photo_6,
R. drawable. gallery_photo_7,
R. drawable. gallery_photo_8,

R. drawable. gallery_photo_1,
R. drawable. gallery_photo_2,
R. drawable. gallery_photo_3,
R. drawable. gallery_photo_4,
R. drawable. gallery_photo_5,
R. drawable. gallery_photo_6,
R. drawable. gallery_photo_7,
R. drawable. gallery_photo_8
};

Public Int Getcount (){
Return IMGs. length;
}

Public Object getitem ( Int ITEM ){
Return Item;
}

Public Long Getitemid ( Int ID ){
Return ID;
}

Public View getview ( Int Position, view convertview, viewgroup parent ){
Imageview = New Imageview (context );
Imageview. setimageresource (IMGs [position]);
Imageview. setscaletype (imageview. scaletype. fit_xy );
Imageview. setlayoutparams ( New Gallery. layoutparams ( 136 , 88 ));

Return Imageview;
}

}
}

/Chapter04_ui_gallery01/RES/layout/Main. xml

 

Code

  <?  XML version = "1.0" encoding = "UTF-8"  ?>  
< Linearlayout Xmlns: Android = "Http://schemas.android.com/apk/res/android"
Android: Orientation = "Vertical"
Android: layout_width = "Fill_parent"
Android: layout_height = "Fill_parent"
>

< Gallery
Android: ID = "@ + ID/gallery01"
Android: layout_width = "Wrap_content"
Android: layout_height = "Wrap_content" >
</ Gallery >

</ Linearlayout >

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.