android--Picture Collection

Source: Internet
Author: User

I. Achieving results

Album set in Android, swipe left or right to see the previous or Next picture

Two. Layout code

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" >    <GalleryAndroid:id= "@+id/gepics"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" /></LinearLayout>

three. Custom Adapter

 PackageCom.git.ch3;ImportAndroid.content.Context;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.widget.BaseAdapter;ImportAndroid.widget.Gallery;ImportAndroid.widget.ImageView; Public classImageadapterextendsBaseadapter {PrivateContext Mycontext; PrivateInteger[] Myimages={r.drawable.pic1, R.drawable.pic2, R.DRAWABLE.PIC3, R.drawable.pic4,        R.DRAWABLE.PIC5, R.drawable.pic6, R.drawable.pic7, r.drawable.pic8};  PublicImageadapter (Context context) { This. mycontext=context; } @Override Public intGetCount () {returnmyimages.length; } @Override PublicObject GetItem (intarg0) {        returnmyimages[arg0]; } @Override Public LongGetitemid (intarg0) {        returnarg0; } @Override PublicView GetView (intarg0, View arg1, ViewGroup arg2) {ImageView View=NewImageView ( This. Mycontext); View.setimageresource ( This. myimages[arg0]);        View.setscaletype (ImageView.ScaleType.FIT_XY); View.setlayoutparams (NewGallery.layoutparams (300, 200)); returnview; }}
Custom Adapter

Custom adapter is primarily useful for specifying the size returned by a picture, and which images are displayed in the specified album set, where 8 images are added in the Systems Engineering Catalog (DRAWABLE-MDPI)

The most important way is to return to the picture view

@Override  Public View GetView (int  arg0, view arg1, ViewGroup arg2) {        ImageView view=new ImageView (  this. mycontext);        View.setimageresource (this. myimages[arg0]);        View.setscaletype (ImageView.ScaleType.FIT_XY);        View.setlayoutparams (new gallery.layoutparams (+));         return view;}

  

Four. Setting up data binding

Gallery gepics=(Gallery) Findviewbyid (r.id.gepics); Gepics.setadapter (new imageadapter (this ));

Use the Setadapter () method to set the data source

android--Picture Collection

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.