Android Desktop Paging

Source: Internet
Author: User

1. Adapter:

Package Com.example.adapter;import Java.util.arraylist;import android.annotation.suppresslint;import;import;import Android.view.View;import Android.view.ViewGroup; Public classMyviewpageradapter extends pageradapter{PrivateArraylist<view>mlist;  PublicMyviewpageradapter (arraylist<view>mlist)        {super ();  This. mlist=mlist; } @Override Public intGetCount () {//TODO auto-generated Method Stub        return  This. mlist==NULL?0: This. Mlist.size (); } @Override Publicboolean isviewfromobject (View arg0, Object arg1) {//TODO auto-generated Method Stub        returnarg0==arg1; }     Public voidDestroyitem (ViewGroup container,intPosition,objectObject) {Container.removeview ( This. mlist.Get(position)); } @SuppressLint ("Newapi")     PublicObject Instantiateitem (ViewGroup container,intposition) {Layoutparams LP=NewLayoutparams (layoutparams.match_parent,layoutparams.match_parent); Container.addview ( This. mlist.Get(position), LP); return  This. mlist.Get(position); }}
Package Com.example.adapter;import java.util.arraylist;import;import android.os.Bundle; Import;import Android.text.layout;import Android.view.view;import Android.view.viewgroup.layoutparams;import Android.widget.imageview;import Android.widget.ImageView.ScaleType; Public classViewpageactivity extends activity{Private int[]imgs={r.drawable.bbe609315da7a9bfa65df713e7c168e0, r.drawable.bc494385774b8343123c5697ebeaeb9, R.DRAWABLE.DD6709AB53006F11F393E58F2BA614C4, r.drawable.e8d145de5ffdf97a4407ab4c5dd33513, R.dr    AWABLE.EECFD0D328203E8A15366658231C3174}; @Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stubsuper.oncreate (savedinstancestate);        Setcontentview (r.layout.viewpagelayout); Viewpager Viewpager=(Viewpager) Findviewbyid (; ArrayList<view>mlist=NewArraylist<view>();  for(intI=0; i) {ImageView Imgview=NewImageView ( This); Imgview.setlayoutparams (NewLayoutparams (layoutparams.match_parent,layoutparams.match_parent));            Imgview.setscaletype (SCALETYPE.FIT_XY);            Imgview.setimageresource (Imgs[i]);        Mlist.add (Imgview); } Myviewpageradapter Adapter=NewMyviewpageradapter (mlist);    Viewpager.setadapter (adapter); }    }

Android Desktop Paging

Related Article

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: 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.