search
Homephp教程php手册【Android】Chapter 5 (8) Picture Gallery (Galery)

Category: C#, Android, VS2015; Creation date: 2016-02-07 1. Introduction The gallery (also called gallery) is a layout widget used to display each picture in a horizontally scrollable list. Currently The selected picture will be centered in the view. Note: Android has deprecated this widget. The reason for deprecation is that the efficiency of using Galery is relatively low,

Category: C#, Android, VS2015;

Creation date: 2016-02-07

1. Introduction

The Gallery (also called Gallery) is a layout widget that displays each 【Android】Chapter 5 (8) Picture Gallery (Galery) in a horizontally scrollable list, with the currently selected 【Android】Chapter 5 (8) Picture Gallery (Galery) placed in the center of the view.

Note: Android has deprecated this widget. The reason for deprecation is that the efficiency of using Galery is relatively low. The official recommendation is to use HorizontalScrollView to replace this widget. However, many 【Android】Chapter 5 (8) Picture Gallery (Galery) browsing functions on mobile phones are currently implemented using Galery. If you still like this widget, you can continue to use it in higher version projects.

1. Running screenshots

Use the mouse left and right to drag and drop the 【Android】Chapter 5 (8) Picture Gallery (Galery) to observe the effect.

【Android】Chapter 5 (8) Picture Gallery (Galery)

2. Add the Demo08Gallery.axml file

<span style="color: #0000ff;"></span><span style="color: #ff00ff;">xml version="1.0" encoding="utf-8"</span><span style="color: #0000ff;">?></span>
<span style="color: #0000ff;"><span style="color: #800000;">LinearLayout </span><span style="color: #ff0000;">xmlns:android</span><span style="color: #0000ff;">="http://schemas.android.com/apk/res/android"</span><span style="color: #ff0000;">
    android:orientation</span><span style="color: #0000ff;">="vertical"</span><span style="color: #ff0000;">
    android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
    android:layout_height</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
    android:gravity</span><span style="color: #0000ff;">="center_vertical"</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">Gallery
        </span><span style="color: #ff0000;">android:id</span><span style="color: #0000ff;">="@+id/gallery"</span><span style="color: #ff0000;">
        android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
        android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span> <span style="color: #0000ff;">/></span>
<span style="color: #0000ff;"></span><span style="color: #800000;">LinearLayout</span><span style="color: #0000ff;">></span></span></span>

Save the file and click the [Refresh] button above the Solution Explorer.

3. Add the Demo08Gallery.cs file

<span style="color: #0000ff;">using</span><span style="color: #000000;"> System;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.App;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Content;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.OS;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Views;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Widget;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> java.Lang;

</span><span style="color: #0000ff;">namespace</span><span style="color: #000000;"> ch05demos.SrcActivity
{
    [Activity(Label </span>= <span style="color: #800000;">"</span><span style="color: #800000;">Demo08Gallery</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> Demo08Gallery : Activity
    {
        </span><span style="color: #0000ff;">PRotected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnCreate(Bundle savedInstanceState)
        {
            </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.demo08_Gallery);
            </span><span style="color: #0000ff;">var</span> g = FindViewById<gallery><span style="color: #000000;">(Resource.Id.gallery);
            g.Adapter </span>= <span style="color: #0000ff;">new</span> ImageAdapter(<span style="color: #0000ff;">this</span><span style="color: #000000;">)
            {
                CurrentWidth </span>= <span style="color: #800080;">550</span><span style="color: #000000;">,
                CurrentHeight </span>= <span style="color: #800080;">550</span><span style="color: #000000;">
            };
            g.ItemClick </span>+=<span style="color: #000000;"> Gallery_ItemClick;
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Gallery_ItemClick(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, AdapterView.ItemClickEventArgs e)
        {
            Toast.MakeText(</span><span style="color: #0000ff;">this</span><span style="color: #000000;">, e.Position.ToString(), ToastLength.Short).Show();
        }
    }
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> ImageAdapter : BaseAdapter
    {
        </span><span style="color: #0000ff;">private</span><span style="color: #000000;"> Context context;
        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">int</span>[] thumbIds =<span style="color: #000000;"> {
            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
        };

        </span><span style="color: #008000;">//</span><span style="color: #008000;">默认值为500(这是C# 6.0新增的功能,仅VS2015可以这样用)</span>
         <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> CurrentWidth { <span style="color: #0000ff;">get</span>; <span style="color: #0000ff;">set</span>; } = <span style="color: #800080;">500</span><span style="color: #000000;">;
        </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> CurrentHeight { <span style="color: #0000ff;">get</span>; <span style="color: #0000ff;">set</span>; } = <span style="color: #800080;">500</span><span style="color: #000000;">;

        </span><span style="color: #0000ff;">public</span><span style="color: #000000;"> ImageAdapter(Context c)
        {
            context </span>=<span style="color: #000000;"> c;
        }

        </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> Count
        {
            </span><span style="color: #0000ff;">get</span> { <span style="color: #0000ff;">return</span><span style="color: #000000;"> thumbIds.Length; }
        }

        </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">override</span> View GetView(<span style="color: #0000ff;">int</span><span style="color: #000000;"> position, View convertView, ViewGroup parent)
        {
            ImageView i </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ImageView(context);
            i.SetImageResource(thumbIds[position]);
            i.LayoutParameters </span>= <span style="color: #0000ff;">new</span> Gallery.LayoutParams(<span style="color: #800080;">500</span>, <span style="color: #800080;">500</span><span style="color: #000000;">);
            i.SetScaleType(ImageView.ScaleType.FitXy);
            </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> i;
        }

        </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">long</span> GetItemId(<span style="color: #0000ff;">int</span><span style="color: #000000;"> position)
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span><span style="color: #000000;">;
        }

        </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">override</span> Java.Lang.Object GetItem(<span style="color: #0000ff;">int</span><span style="color: #000000;"> position)
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span><span style="color: #000000;">;
        }
    }
}</span></gallery>

Run.


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),