Android Picture Carousel

Source: Internet
Author: User

Recently found a fun thing to picture carousel. I found this in the Web page, but the page is particularly simple, very easy to implement, then how to achieve in Android, I looked at the information in the case, found that there is really a control, very simple, just a little bit of code can be achieved. Let's take a look at it below.

First, import the control and import the package in Gradle:

1:


Effect

The mainactivity code is as follows:

 Packagecom.example.double2.rollviewpagertest; ImportAndroid.graphics.Color; ImportAndroid.os.Bundle; Importandroid.support.v7.app.AppCompatActivity; ImportAndroid.view.Menu; ImportAndroid.view.MenuItem; ImportAndroid.view.View; ImportAndroid.view.ViewGroup; ImportAndroid.widget.ImageView; ImportCom.jude.rollviewpager.RollPagerView; ImportCom.jude.rollviewpager.adapter.StaticPagerAdapter; ImportCom.jude.rollviewpager.hintview.ColorPointHintView;  Public classMainactivityextendsappcompatactivity {PrivateRollpagerview Mrollviewpager; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);            Setcontentview (R.layout.activity_main); Mrollviewpager=(Rollpagerview) Findviewbyid (R.id.roll_view_pager); //Set playback time intervalMrollviewpager.setplaydelay (1000); //Set TransparencyMrollviewpager.setanimationdurtion (500); //setting up the adapterMrollviewpager.setadapter (NewTestnormaladapter ()); //Set the indicator (sequentially)//Custom Indicator Picture//Set the dot indicator color//Set Text indicator//Hide Indicator//Mrollviewpager.sethintview (New Iconhintview (this, R.drawable.point_focus, R.drawable.point_normal)); Mrollviewpager.sethintview (NewColorpointhintview ( This, Color.yellow,color.white)); //Mrollviewpager.sethintview (New Texthintview (this)); //Mrollviewpager.sethintview (NULL);     }        }  

To create an adapter:

Private classTestnormaladapterextendsStaticpageradapter {Private int[] IMGs ={Below is your own picture, R.drawable.a, r.drawable.b, r.drawable.c,              R.DRAWABLE.D,}; @Override PublicView GetView (ViewGroup container,intposition) {ImageView View=NewImageView (Container.getcontext ());              View.setimageresource (Imgs[position]);              View.setscaletype (ImageView.ScaleType.CENTER_CROP); View.setlayoutparams (Newviewgroup.layoutparams (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); returnview; } @Override Public intGetCount () {returnimgs.length; }      }    

Layout file:

<?XML version= "1.0" encoding= "Utf-8"?>  <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:app= "Http://schemas.android.com/apk/res-auto"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context=". Mainactivity ">        <Com.jude.rollviewpager.RollPagerViewAndroid:id= "@+id/roll_view_pager"Android:layout_width= "Match_parent"Android:layout_height= "180DP"App:rollviewpager_play_delay= " the"/>  </Relativelayout>  

Come on and practice it.

Android Picture Carousel

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