Album created by Android-pretty good results

Source: Internet
Author: User

 

This is a small program I made when learning Android. The main function of the program is to implement the mini album function, which can be seen on the virtual machine.

I set the screen size to 800*600

 

/*

* Imageswitchergallery. Java

*/

 

Package Android. study_layout;

 

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. View. window;
Import Android. View. animation. animationutils;
Import Android. widget .*;
Import Android. widget. adapterview. onitemselectedlistener;
Import Android. widget. viewswitcher. viewfactory;

 

Public class imageswitchergallery extends activity implements
Onitemselectedlistener, viewfactory {
Private imageswitcher image_switcher;
Private gallery Gallery;

Private integer [] mthumbids = {R. drawable. A1, R. drawable. A2,
R. drawable. A3, R. drawable. A4, R. drawable. A5,
};

Private integer [] mimageids = {R. drawable. A1, R. drawable. A2,
R. drawable. A3, R. drawable. A4, R. drawable. A5 ,};

@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Requestwindowfeature (window. feature_no_title );
Setcontentview (R. layout. image_switcher_gallery );

Image_switcher = (imageswitcher) findviewbyid (R. Id. switcher );
Image_switcher.setfactory (this );

Image_switcher.setinanimation (animationutils. loadanimation (this,
Android. R. anim. fade_in ));
Image_switcher.setoutanimation (animationutils. loadanimation (this,
Android. R. anim. fade_out ));

Gallery = (Gallery) findviewbyid (R. Id. Gallery );

Gallery. setadapter (New imageadapter (this ));
Gallery. setonitemselectedlistener (this );
}

@ Override
Public View makeview (){
Imageview image = new imageview (this );
Image. setbackgroundcolor (0xff000000 );
Image. setscaletype (imageview. scaletype. fit_xy );
Image. setlayoutparams (New imageswitcher. layoutparams (
Layoutparams. match_parent, layoutparams. match_parent ));
Return image;
}

Public class imageadapter extends baseadapter {
Public imageadapter (context c ){
Mcontext = C;
}

Public int getcount (){
Return mthumbids. length;
}

Public object getitem (INT position ){
Return position;
}

Public long getitemid (INT position ){
Return position;
}

Public View getview (INT position, view convertview, viewgroup parent ){
Imageview image = new imageview (mcontext );

Image. setimageresource (mthumbids [position]);
Image. setadjustviewbounds (true );
Image. setlayoutparams (new gallery. layoutparams (
Layoutparams. wrap_content, layoutparams. wrap_content ));
Return image;
}

Private context mcontext;

}

@ Override
Public void onitemselected (adapterview <?> Parent, view, int position,
Long ID ){
Imageswitcher image_switcher = (imageswitcher) findviewbyid (R. Id. switcher );
Image_switcher.setimageresource (mimageids [position]);

}

@ Override
Public void onnothingselected (adapterview <?> Parent ){
}
}

 

XML file

<? XML version = "1.0" encoding = "UTF-8"?>
<Relativelayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: Orientation = "vertical">

<Imageswitcher
Android: Id = "@ + ID/switcher"
Android: layout_width = "match_parent"
Android: layout_height = "450dip"
Android: layout_alignparentleft = "true"
Android: layout_alignparenttop = "true"
/>

<Gallery
Android: Id = "@ + ID/Gallery"
Android: layout_width = "fill_parent"
Android: layout_height = "120dip"
Android: Background = "#55000000"
Android: layout_alignparentleft = "true"
Android: layout_alignparentbottom = "true"
Android: gravity = "center_vertical"
Android: spacing = "30dip"
/>

</Relativelayout>

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.