Gallery Android Tutorial -
here code. want create image gallery succesfully did. want click on thumbnail appear @ bigger scale below gallery or maybe @ center of screen. should use setimageresource() method?
<?xml version="1.0" encoding="utf-8"?> <gallery xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="wrap_content" />
i have tried starters put imageview below gallery,but compiler gave me error.
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="galleryactivity"> <attr name="android:galleryitembackground" /> </declare-styleable> </resources> public class galleryactivity extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); gallery g = (gallery) findviewbyid(r.id.gallery); g.setadapter(new imageadapter(this)); g.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { toast.maketext(galleryactivity.this, "" + position, toast.length_short).show(); } }); } public class imageadapter extends baseadapter { int mgalleryitembackground; private context mcontext; private integer[] mimageids = { r.drawable.sample_1, r.drawable.sample_2, r.drawable.sample_3, r.drawable.sample_4, r.drawable.sample_5, r.drawable.sample_6, r.drawable.sample_7 }; public imageadapter(context c) { mcontext = c; typedarray = obtainstyledattributes(r.styleable.galleryactivity); mgalleryitembackground = a.getresourceid( r.styleable.galleryactivity_android_galleryitembackground, 0); a.recycle(); } public int getcount() { return mimageids.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 = new imageview(mcontext); i.setimageresource(mimageids[position]); i.setlayoutparams(new gallery.layoutparams(300, 220)); i.setscaletype(imageview.scaletype.fit_xy); i.setbackgroundresource(mgalleryitembackground); return i; } } }
thank in advance reading code. useful.
greetings, theo
Comments
Post a Comment