Wang Liping -- Gallery: sliding the left and right sides of the image

Source: Internet
Author: User


<Span style = "font-size: 18px; color: #330033;"> package COM. main; import android. app. activity; import android. content. context; import android. OS. bundle; import android. view. view; import android. view. viewgroup; import android. widget. baseadapter; import android. widget. gallery; import android. widget. imageview; @ suppresswarnings ("deprecation") public class mainactivity extends activity {gallery Gallery; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); gallery = (Gallery) findviewbyid (R. id. gallery); Gallery. setadapter (New imageadapter (this); Gallery. pointtoposition (0, 0);} class imageadapter extends baseadapter {private context; // image source array private integer [] imageinteger = {R. drawable. ic_launcher, R. drawable. bg3, R. drawable. ic_launcher, R. drawable. bg3, R. drawable. ic_launcher, R. drawable. bg3, R. drawable. ic_launcher, R. drawable. bg3}; Public imageadapter (context c) {context = C ;}@ override public int getcount () {return imageinteger. length ;}@ override public object getitem (INT position) {return position ;}@ override public long getitemid (INT position) {// todo auto-generated method stub return position ;} @ override public view getview (INT position, view convertview, viewgroup parent) {imageview = new imageview (context); imageview. setimageresource (imageinteger [position]); imageview. setscaletype (imageview. scaletype. fit_xy); Return imageview ;}}</span>
Bytes -----------------------------------------------------------------------------------------
<span style="font-size:18px;color:#330033;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >        <Gallery        android:id="@+id/gallery"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:layout_alignParentTop="true"        android:gravity="fill_vertical"        android:spacing="10dp"        android:background="#0000FF"        android:padding="0dp"        />    </RelativeLayout> </span>






Wang Liping -- Gallery: sliding the left and right sides of the image

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.