GitHub Address: Https://github.com/Trinea/android-auto-scroll-view-pager
Gradle:
Compile (' cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2 ') { ' Support-v4 '}
class cn.trinea.android.** {*;} class cn.trinea.android.** {*;} -dontwarn cn.trinea.android.**
Layout file
<Cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPagerAndroid:id= "@+id/auto_view_pager"Android:layout_width= "Match_parent"Android:layout_height= "320DP" /> <LinearLayoutAndroid:id= "@+id/point_group"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:layout_gravity= "Center_horizontal"android:gravity= "Center"Android:layout_alignparentbottom= "true"android:orientation= "Horizontal"Android:paddingbottom= "5DP" >
Code settings:
if(Imagelist.size () ==1) {auto_view_pager.stopautoscroll (); } auto_view_pager.setadapter (NewMyadapter (imageList));// //Setting the delay timeAuto_view_pager.setinterval (5000); //set the direction of the carousel Autoscrollviewpager.right/autoscrollviewpager.leftauto_view_pager.setdirection (autoscrollviewpager.right); //set whether to automatically cycle the carousel, default to True//Note: Once set to true, it cannot be used with ViewpagerindicatorAuto_view_pager.setcycle (true); //set the length of time to toggle animationsAuto_view_pager.setscrolldurationfactor (5); //set how to toggle the next one when you swipe to the last or the first one//true if animation is turned on when sliding to the last or first sheetAuto_view_pager.setborderanimation (true); //Stop the carousel when you touchAuto_view_pager.setstopscrollwhentouch (true);//// //resolve the last jump to the first flashing question//Auto_view_pager.setcurrentitem ((INTEGER.MAX_VALUE/2-integer.max_value/2% imagelist.size ()));Auto_view_pager.setcurrentitem (imagelist.size ()*10); FinalLinearLayout Point_group =(LinearLayout) Findviewbyid (R.id.point_group); Point_group.removeallviews (); for(inti = 0; I < imagelist.size (); i++) { //add an indication pointImageView point =NewImageView (detailactivity. This); Linearlayout.layoutparams params=Newlinearlayout.layoutparams (ViewGroup.LayoutParams.WRAP_CONTENT, viewgroup.layou Tparams.wrap_content); Params.rightmargin= 10; Point.setlayoutparams (params); Point.setbackgroundresource (R.DRAWABLE.POINT_BG); if(i = = 0) {point.setenabled (true); } Else{point.setenabled (false); } point_group.addview (point); }//Auto_view_pager.addonpagechangelistener (NewViewpager.onpagechangelistener () {@Override Public voidOnpagescrolled (intPositionfloatPositionoffset,intpositionoffsetpixels) {} @Override Public voidOnpageselected (intposition) {LOG.E ("TAG", "position" +position); //change the state of the indicator point//Enbale The current point to true Try{point_group.getchildat (position% Imagelist.size ()). SetEnabled (true); //set the previous point to falsePoint_group.getchildat (lastposition). setenabled (false); Lastposition= Position%imagelist.size (); } Catch(Exception e) {}} @Override Public voidOnpagescrollstatechanged (intState ) { } });
Adapter
classMyadapterextendsPageradapter {List<String>msimpledraweeviewlist; PublicMyadapter (list<string>msimpledraweeviewlist) { This. msimpledraweeviewlist=msimpledraweeviewlist; } @Override Public intGetCount () {returnInteger.max_value; } @Override Public Booleanisviewfromobject (View view, Object object) {returnView = =object; } @Override Public voidDestroyitem (ViewGroup container,intposition, Object object) {Container.removeview (View) object); } @Override PublicObject Instantiateitem (ViewGroup container,intposition) {URI Uri= Uri.parse (httpbase.host_string + "/" + msimpledraweeviewlist.get (position%)msimpledraweeviewlist.size ()));//Simpledraweeview Draweeview = new Simpledraweeview (detailactivity.this);SimpledraweeviewDraweeview= (Simpledraweeview) view.inflate (detailactivity. This, R.layout.layout_image,NULL). Findviewbyid (R.id.image1); Draweeview. Setscaletype (ImageView.ScaleType.FIT_XY); Viewgroup.layoutparams Imagebtn_params=NewViewgroup.layoutparams (Autoutils.getdisplaywidthvalue (720), Autoutils.getdisplayheightvalue (640)); Draweeview. Setlayoutparams (Imagebtn_params); Draweeview. Setimageuri (URI);//ImageView im= New ImageView (detailactivity.this);//Picasso.with (detailactivity.this). Load (httpbase.host_string + "/" + msimpledraweeviewlist.get (position% mSi Mpledraweeviewlist.size ())). into (IM);viewparent Parent= draweeview. getParent (); //Remove view has been added to a parent control before it is reported as an exception if(Parent! =NULL) {ViewGroup Group=(viewgroup) parent; Group.removeview (Draweeview); } container.addview (draweeview); return Draweeview;//Container.addview (images.get (position% images.size ()));//return Images.get (position% images.size ());//Container.addview (draweeview);//return draweeview; } }
@Overrideprotected voidOnresume () {Super. Onresume (); //turn on auto-carousel, Delay Time is getinterval ()Auto_view_pager.startautoscroll (); //turn on automatic carousel and set the delay//Auto_view_pager.startautoscroll (delaytime);} @Overrideprotected voidOnPause () {Super. OnPause (); //Stop CarouselAuto_view_pager.stopautoscroll (); }
Point_bg.xml
<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android" > <Itemandroid:drawable= "@drawable/point_nomal"android:state_enabled= "true"/> <Itemandroid:drawable= "@drawable/point_focured"android:state_enabled= "false"/></selector>
Point_focured.xml
<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android"Android:shape= "Oval" > <sizeAndroid:width= "5DP"Android:height= "5DP"/> <SolidAndroid:color= "#33000000"/></Shape>
Point_nomal.xml
<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android"Android:shape= "Oval" > <sizeAndroid:width= "5DP"Android:height= "5DP"/> <SolidAndroid:color= "#aaFFFFFF"/></Shape>
Android-auto-scroll-view-pager (unlimited ad carousel map)