Android Auto-cycle scrolling pictures (ads) with navigation dots

Source: Internet
Author: User

Using ViewPage to realize scrolling picture, auto-loop effect, small dot with navigation

As follows:



Preparatory work:

Download my packaged jar package and put it in the project's Libs folder.

: http://download.csdn.net/detail/u012027644/8744019


How to use:

Activity's Code:

public class Mainactivity extends Activity {myimgscroll mypager;//Picture container linearlayout ovallayout;//dot Container private List<vi Ew> ListViews; ImageView Group Private list<string> urllist; Picture Address list @overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Mypager = (Myimgscroll) Findviewbyid (R.ID.MYVP); ovalLayout = (LinearLayout) Findviewbyid (R.id.vb); Geyimageurl ();//Get Picture address initviewpager ();//Initialize picture//start scrolling Mypager.start (this, listviews, 4000, Ovallayout);} /** * Network picture address set */private void Geyimageurl () {urllist = new arraylist<string> (); Urllist.add ("http:// Img3.imgtn.bdimg.com/it/u=4062712383,3140853232&fm=21&gp=0.jpg "); Urllist.add (" http://pic.58pic.com/ 58pic/15/16/00/49t58picizm_1024.jpg "); Urllist.add (" http://www.6188.com/upload_6188s/Small_paper/tebie/3553/ S800/2880view_008.jpg "); Urllist.add (" http://img4.imgtn.bdimg.com/it/u=1254729582,2442676828&fm=21&gp=    0.jpg ");} @Overrideprotected void Onrestart() {Mypager.starttimer (); Super.onrestart ();} @Overrideprotected void OnStop () {Mypager.stoptimer (); Super.onstop ();} public void Stop (View v) {Mypager.stoptimer ();} /** * Initialize picture */private void Initviewpager () {listviews = new arraylist<view> ();//Initialize Volleyrequestqueue Mqueue = Volle Y.newrequestqueue (this); Imageloader Imageloader = new Imageloader (Mqueue, New Imagecache () {@Override public vo ID putbitmap (string url, Bitmap Bitmap) {} @Override public Bitmap getbitmap (string url) {Retu      RN null; }});//Loop add imageviewfor (int i = 0; i < urllist.size (); i++) {Networkimageview ImageView = new Networkimageview (this); Imageview.setscaletype (Scaletype.center_crop); Imageview.setdefaultimageresid (R.drawable.ic_launcher); Imageview.seterrorimageresid (R.drawable.ic_launcher); Imageview.setimageurl (Urllist.get (i), imageLoader); Listviews.add (ImageView);}}}

Note: the example uses a network frame to get the network picture volley

Here's what I packed up:

http://download.csdn.net/detail/u012027644/8547825

Add libs after download


If the local images do not need to be obtained from the Internet can change the Networkimageview to ImageView, here the method will not repeat.


XML code:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android:orientation= "vertical" >    <com.joe.imgscroll.myimgscroll        android:id= "@+id/myvp"        Android:layout_width= "Match_parent"        android:layout_height= "220DP"/>    <linearlayout        android:id = "@+id/vb"        android:layout_width= "match_parent"        android:layout_height= "10DP"        android:layout_ margintop= "3DP"        android:gravity= "center"        android:orientation= "Horizontal" >    </linearlayout ></LinearLayout>

the ID of the VB linearlayout is a container for the navigation of small dots, also can not.


Last Demo project: Https://github.com/yangjie10930/ImageScroll

Android Auto-cycle scrolling pictures (ads) with navigation dots

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.