Android uses gallery components for picture playback preview

Source: Internet
Author: User

Gallery (Gallery ) expands the layoutparams to provide a place to accommodate current transformation information and previous location conversion information.

Activity
Package Com.app.test01;import Com.app.adapter.imageadapter;import android.app.activity;import Android.os.bundle;import Android.view.view;import Android.widget.adapterview;import Android.widget.Gallery;import Android.widget.ImageView; Public classGallerytest extends activity{Gallery Gallery;    ImageView Imagedemo; Imageadapter Iadapter=NewImageadapter ( This); @Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stubsuper.oncreate (savedinstancestate);                Setcontentview (R.layout.activity_gallery); Gallery=(Gallery) Findviewbyid (r.id.gallery1); Imagedemo=(ImageView) Findviewbyid (R.id.imagedemo);        Gallery.setadapter (Iadapter); Gallery.setonitemclicklistener (NewAdapterview.onitemclicklistener () {@Override Public voidOnitemclick (adapterview<?>Parent, view view,intPositionLongID) {//TODO auto-generated Method Stubinteger[] Iviews =Iadapter.getmimageids ();            Imagedemo.setimagedrawable (Getresources (). getdrawable (Iviews[position]));    }        }); }}
Baseadapter Adapter
Package Com.app.adapter;import Com.app.test01.r;import android.content.context;import Android.content.res.typedarray;import Android.view.view;import Android.view.viewgroup;import Android.widget.baseadapter;import Android.widget.gallery;import Android.widget.ImageView; Public classImageadapter extends Baseadapter {PrivateContext Mcontext;  PublicImageadapter (Context c) {Mcontext=C; }     Public intGetCount () {returnmimageids.length; }     PublicObject GetItem (intposition) {        returnposition; }     Public LongGetitemid (intposition) {        returnposition; }     PublicView GetView (intposition, View Convertview, ViewGroup parent) {ImageView I=NewImageView (Mcontext);        I.setimageresource (Mimageids[position]); I.setlayoutparams (NewGallery.layoutparams ( Max, the)); returni; }     Publicinteger[] Getmimageids () {returnMimageids; }     Public voidsetmimageids (integer[] mimageids) { This. Mimageids =Mimageids; }    Privateinteger[] Mimageids ={r.drawable.image01, r.drawable.image02, R.drawable.image03, r.drawable. Image04, R.drawable.image05, R.drawable.image06, R.drawable.image07, r.drawabl E.image08, R.drawable.image09, R.drawable.image01, R.DRAWABLE.IMAGE02, R.drawa BLE.IMAGE03, R.drawable.image04, R.drawable.image05, R.drawable.image06, R.dra Wable.image07, R.drawable.image08, R.drawable.image09,};}
XML layout file
<?xml version="1.0"encoding="Utf-8"? ><linearlayout xmlns:android="http://schemas.android.com/apk/res/android"Android:layout_width="match_parent"Android:layout_height="match_parent"android:orientation="Vertical"> <Gallery Android:id="@+id/gallery1"Android:layout_width="match_parent"Android:layout_height="wrap_content"Android:layout_margintop="50DP"/> <relativelayout android:layout_width="match_parent"Android:layout_height="match_parent"android:gravity="Center"> <ImageView Android:id="@+id/imagedemo"Android:layout_width="wrap_content"Android:layout_height="wrap_content"android:src="@drawable/image01"/> </RelativeLayout></LinearLayout>

Android uses gallery components for picture playback preview

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.