5th Chapter (8) Photo Gallery (Galery)

Source: Internet
Author: User

Category: C #, Android, VS2015;

Date Created: 2016-02-07 I. INTRODUCTION

Gallery (also called gallery) is a layout widget that displays each picture in a horizontally scrollable list, and the currently selected picture is placed in the center of the view.

Note: Android has deprecated this widget, and the reason for deprecation is that it is less efficient with galery, and the official recommendation is instead to replace the widget with Horizontalscrollview. However, many of the picture-browsing features on your phone are now implemented with galery, and if you still like the widget, you can continue to use it in a high-build project. Second, example 8--demo08gallery

1. Operation

Use the mouse to drag and drop pictures in the simulator to observe the effect.

2. Add Demo08gallery.axml File

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

Save the file, and then click the Refresh button above Solution Explorer.

3. Add Demo08Gallery.cs File

usingSystem;usingAndroid.app;usingandroid.content;usingAndroid.os;usingandroid.views;usingAndroid.widget;usingJava.lang;namespaceCh05demos. srcactivity{[Activity (Label="Demo08actionbar")]     Public classdemo08gallery:activity {protected Override voidOnCreate (Bundle savedinstancestate) {Base.            OnCreate (savedinstancestate);            Setcontentview (Resource.Layout.demo08_Gallery); varg = findviewbyid<gallery>(Resource.Id.gallery); G.adapter=NewImageadapter ( This) {Currentwidth=550, Currentheight=550            }; G.itemclick+=Gallery_itemclick; }        Private voidGallery_itemclick (Objectsender, Adapterview.itemclickeventargs e) {Toast.maketext ( This, E.position.tostring (), Toastlength.short).        Show (); }    }     Public classImageadapter:baseadapter {Privatecontext Context; Private int[] Thumbids ={Resource.Drawable.sample_1, Resource.Drawable.sample_2, Resource.Drawable.sample_3            , Resource.Drawable.sample_4, Resource.Drawable.sample_5, Resource.Drawable.sample_6,        Resource.Drawable.sample_7}; //The default value is 500 (this is a new feature of C # 6.0, only VS2015 can use this)         Public intCurrentwidth {Get;Set; } = -;  Public intCurrentheight {Get;Set; } = -;  PublicImageadapter (context C) {context=C; }         Public Override intCount {Get{returnThumbids.length;} }         Public OverrideView GetView (intposition, View Convertview, ViewGroup parent) {ImageView I=NewImageView (context);            I.setimageresource (Thumbids[position]); I.layoutparameters=NewGallery.layoutparams ( -, -);            I.setscaletype (ImageView.ScaleType.FitXy); returni; }         Public Override LongGetitemid (intposition) {            return 0; }         Public OverrideJava.Lang.Object GetItem (intposition) {            return NULL; }    }}

Run.

5th Chapter (8) Photo Gallery (Galery)

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.