<span id="Label3"></p><p><p><span style="line-height: 1.5;">Gallery==> Gallery View</span></p></p><p><p>Gallery and Spinnery are the same--absspinner, indicating that both Garrey and spinner are a list box.</p></p><p><p>The difference between the two is:<strong>spinner shows a vertical list box, gallery displays a horizontal list box</strong> ;</p></p><p><p>The role of spinner is for the user to choose, while gallery allows the user to drag to view the previous and next list Items.</p></p><p><p>Garrey Common XML Attributes:</p></p> <table style="height: 88px; width: 689px;" border="0" align="left"> <tbody> <tr> <td><strong><span style="font-size: 13px;">Android:animationduration</span></strong></td> <td><strong><span style="font-size: 13px;">Setanimationduration (int)</span></strong></td> <td><strong><span style="font-size: 13px;">Set the animation frame duration when a list item is toggled</span></strong></td> </tr> <tr> <td><strong><span style="font-size: 13px;">Android:gravity</span></strong></td> <td><strong><span style="font-size: 13px;">Setgravity (int)</span></strong></td> <td><strong><span style="font-size: 13px;">Set the way to it</span></strong></td> </tr> <tr> <td><strong><span style="font-size: 13px;">Android:spacing</span></strong></td> <td><strong><span style="font-size: 13px;">Setspacing (int)</span></strong></td> <td><strong><span style="font-size: 13px;">Set the spacing between list items within a gallery</span></strong></td> </tr> <tr> <td><strong><span style="font-size: 13px;">Android:unselectedalpha</span></strong></td> <td><strong><span style="font-size: 13px;">Setunselectedalpha (float)</span></strong></td> <td><strong><span style="font-size: 13px;">Sets the transparency of a list item that is not selected</span></strong></td> </tr> </tbody> </table><p><p></p></p><p><p></p></p><p><p></p></p><p><p>Attention:</p></p><p><p>Gallery usage is similar to spinner, using adapter to provide a data source, the view returned by adapter GetView () will be the list item of the gallery list;</p></p><p><p>Monitor the selection changes through the Onitemselectedlistener listener.</p></p><p><p><strong>Instance One</strong></p></p><pre class="brush:csharp;gutter:true;">Layout file = = "<linearlayout xmlns:android=" http://schemas.android.com/apk/res/android "xmlns:tools="/http Schemas.android.com/tools "android:orientation=" Vertical "android:layout_width=" match_parent "android:layout_heig ht= "match_parent" tools:context= ". Mainactivity "> <imageswitcher android:id=" @+id/switcher "android:layout_width=" 320dp "andro id:layout_height= "320dp"/> <gallery android:id= "@+id/gallery" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:spacing= "3pt" android:unselectedalpha= "0.6"/></li nearlayout> code Implementation = = "package Com.example.mygrallery;import android.os.bundle;import Android.annotation.suppresslint;import Android.app.activity;import Android.app.actionbar.layoutparams;import Android.content.res.typedarray;import Android.view.menu;import Android.view.view;import android.view.ViewGroup; Import Android.view.animation.animationutils;import Android.widgeT.adapterview;import Android.widget.adapterview.onitemselectedlistener;import Android.widget.BaseAdapter;import Android.widget.gallery;import Android.widget.imageswitcher;import Android.widget.imageview;import android.widget.ViewSwitcher.ViewFactory; @SuppressWarnings ("deprecation") @SuppressLint ("inlinedapi") public class Mainactivity extends activity{private int[] imageids = new int[]{r.drawable.one, r.drawable.tw, r.drawable.th, R.drawabl e.eight, r.drawable.ele,r.drawable.five, r.drawable.four, r.drawable.nice, r.drawable.seven, R.drawable.six, r.drawable.sl, r.drawable.ss, r.drawable.sw, r.drawable.ten, r.drawable.tw,r.drawable.oneowne}; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); setcontentview (r.layout.activity_ main), final Imageswitcher switcher = (imageswitcher) This.findviewbyid (r.id.switcher); final Gallery Gallery = (Gallery) This.findviewbyid (r.id.gallery); switcher.setfactory (new viewfactory () {@Overridepublic View makeview () {ImaGeview img = new ImageView (mainactivity.this); img.setbackgroundcolor (0xff0000); img.setscaletype ( ImageView.ScaleType.FIT_CENTER); img.setlayoutparams (new imageswitcher.layoutparams (layoutparams.wrap_content, layoutparams.wrap_content)); return img;}}); /set Picture Replacement animation effect Switcher.setinanimation (animationutils.loadanimation (this, android. r.anim.fade_in)); switcher.setoutanimation (animationutils.loadanimation (this, android. R.anim.fade_out));//create DataAdapter object, provide data for gallery Baseadapter adapter = new Baseadapter () {@Overridepublic int GetCount () {//TODO auto-generated Method Stubreturn imageids.length;} @Overridepublic Object getItem (int position) {//TODO auto-generated method Stubreturn position;} @Overridepublic long getitemid (int position) {//TODO auto-generated method Stubreturn position;} @Overridepublic View GetView (int position, view convertview, viewgroup parent) {ImageView img = new ImageView (mainactivity . this); Img.setimageresource (imageids[position% imageids.length]);//set The zoom type of the ImageView Img.setscaLetype (ImageView.ScaleType.FIT_XY); img.setlayoutparams (new gallery.layoutparams);//TypedArray arr= Obtainstyledattributes (R.) Img.setbackgroundresource (resid); return img;}}; Gallery.setadapter (adapter); gallery.setonitemselectedlistener (new onitemselectedlistener () {@Overridepublic void onitemselected (adapterview<?> parent, View view, int position, long id) {//TODO auto-generated method Stubswitcher. Setimageresource (imageids[position% imageids.length]);} @Overridepublic void onnothingselected (adapterview<?> parent) {//TODO auto-generated method stub}}); @Overridepublic boolean oncreateoptionsmenu (menu menu) {//inflate The menu; this adds items to the action Bar if it is pre Sent.getmenuinflater (). Inflate (r.menu.main, menu); return true;}}</pre><p><p>The implementation results are as Follows:</p></p><p><p></p></p><p><p></p></p><p><p>Android Learning Note 15--galley</p></p></span>
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