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