Using the Androidscreenslidepager Open Source Library

Source: Internet
Author: User

One

Https://github.com/LyndonChin/AndroidScreenSlidePager

Click the Download Zip button on the right to download it. Then unzip to Local.

Ii. Methods of Use

1. Copy androidscreenslidepager-master\slidepageindicator\src\main\java\com\liangfeizc\ The Pageindicator.java file in the Slidepageindicator directory to any package in the project. and three files in the Drawable folder in the Androidscreenslidepager-master\slidepageindicator\src\main\res directory are copied to the appropriate location in the project

Then copy the code from styles inside the values folder in the Androidscreenslidepager-master\slidepageindicator\src\main\res directory to the project's Styles.xml file.

2, I use the layout framework is viewpager+fragment, and then use Volley (Networkimageview) in the fragment to show the picture.

The key code is as follows:

Private Static Final New string[] {        "http://img1.cache.netease.com/catchpic/B/B2/B2F274C1CCD5A89133261E6252A0C8E9.jpg",         "Http://img5.duitang.com/uploads/item/201408/09/20140809204759_CwtQN.jpeg",        "http/// Img5q.duitang.com/uploads/item/201204/06/20120406151343_hefme.jpeg ",        "/http// Images.qianlong.com/mmsource/imghylanda/201108/25/21/7131919880274907937.jpg ",        "/http// Imgsrc.baidu.com/forum/pic/item/78370e46f91582056a63e576.jpg "};

Layout file:

CirclePageIndicatorand shoud be used as the child views of ViewPager a Framelayout . But here we used merge instead, because the root view with any activity is a FrameLayout . You can use to position the and use to android:gravity CirclePageIndicator adjust the spacing between and the app:indicator_spacing adjencent circle indicators.

<?XML version= "1.0" encoding= "Utf-8"?><Mergexmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:app= "Http://schemas.android.com/apk/res-auto"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" >        <!--Viewpager: Picture Show -    <Android.support.v4.view.ViewPagerAndroid:id= "@+id/pager"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" />    <!--Indicator Dots -    <Com.why.screenslidepagerdemo.custom.PageIndicatorAndroid:id= "@+id/indicator"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_marginbottom= "20DP"Android:layout_marginleft= "20DP"Android:layout_marginstart= "20DP"android:gravity= "Bottom|center_horizontal"app:indicator_spacing= "5DP"App:indicator_type= "fraction" />        </Merge>
Activity_slidepager


Java code:

PrivateViewpager Pager;//Picture ViewpagerPrivateSlidepageradapter adapter;//Viewpager Adapter    PrivatePageindicator indicator;//indicatorPrivateString[] Picsarray;//an array of image URL addresses//Initializing the control    Private voidInitview () {pager=(Viewpager) Findviewbyid (R.id.pager); Indicator=(Pageindicator) Findviewbyid (r.id.indicator); }        //Initializing the adapter    Private voidInitadapter () {Adapter=NewSlidepageradapter (Getsupportfragmentmanager (), Arrays.aslist (Picsarray));    Pager.setadapter (adapter); }            //Initializing Listener Events    Private voidinitevent () {Indicator.setviewpager (pager);//This is the key code for the correlation indicator classIndicator.setindicatortype (PageIndicator.IndicatorType.CIRCLE); }

Menu code on the right:

@Override Public BooleanOncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.slidepager, menu); return true; } @Override Public Booleanonoptionsitemselected (MenuItem item) {intID =Item.getitemid (); if(id = =r.id.action_indicator_circle)        {Indicator.setindicatortype (PageIndicator.IndicatorType.CIRCLE); }Else if(id = =r.id.action_indicator_fraction)        {Indicator.setindicatortype (PageIndicator.IndicatorType.FRACTION); }        return Super. onoptionsitemselected (item); }


:

Using the Androidscreenslidepager Open Source Library

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.