Android Carousel Diagram

Source: Internet
Author: User

Package Com.example.carson_ho.android_banner;

Import Android.os.Bundle;
Import android.support.v7.app.AppCompatActivity;
Import Android.util.Log;
Import Android.view.View;
Import Android.widget.ImageView;
Import Android.widget.Toast;

Import Com.bumptech.glide.Glide;
Import Com.youth.banner.Banner;

public class Mainactivity extends Appcompatactivity {
Private Banner Banner;
Set up a picture resource: URL or local resource
String[] images= new string[] {
"Http://img.zcool.cn/community/018fdb56e1428632f875520f7b67cb.jpg",
"Http://img.zcool.cn/community/01c8dc56e1428e6ac72531cbaa5f2c.jpg",
"Http://img.zcool.cn/community/01fda356640b706ac725b2c8b99b08.jpg",
"Http://img.zcool.cn/community/01fd2756e142716ac72531cbf8bbbf.jpg",
"Http://img.zcool.cn/community/0114a856640b6d32f87545731c076a.jpg"};

Set Picture title: auto-corresponding
String[] Titles=new string[]{"12 while Now", "Hi buy 50 percent do not stop, 12.12 while now", "real deal Big Top top Top"};
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);


Banner = (banner) Findviewbyid (R.id.banner);

Set style, default: Banner.not_indicator (no indicator and title)
The optional styles are as follows:
1. Banner.circle_indicator Display Circular Indicator
2. Banner.num_indicator Display Digital Indicator
3. Banner.num_indicator_title displaying digital indicators and headings
4. Banner.circle_indicator_title Display Circular Indicator and caption
Banner.setbannerstyle (Banner.circle_indicator_title);

Set the Carousel style (no caption defaults to the right and left by default when heading)
Optional styles:
Banner.left Indicator left
Banner.center Indicator Center
Banner.right indicator Right
Banner.setindicatorgravity (Banner.center);

Sets the title and picture to be displayed for the carousel (if not, the title is not displayed by default)
Banner.setbannertitle (titles);

Set whether auto-carousel (default is not set automatically)
Banner.isautoplay (TRUE);

Set the carousel picture interval (do not set default to 2000)
Banner.setdelaytime (5000);
Set up a picture resource: Optional image URL/resource file, default loading with glide, and customizable picture loading frame
All set parameter methods are placed before this method is executed
Banner.setimages (images);

Custom Picture Loading frame
Banner.setimages (Images, new Banner.onloadimagelistener () {
@Override
public void Onloadimage (ImageView view, Object URL) {
System.out.println ("Loading in");
Glide.with (Getapplicationcontext ()). Load (URL). into (view);
System.out.println ("finished loading");
}
});
Set the Click event, the subscript is starting from 1
Banner.setonbannerclicklistener (New Banner.onbannerclicklistener () {//Set Click events
@Override
public void Onbannerclick (view view, int position) {
Toast.maketext (Getapplicationcontext (), "you clicked:" + position, Toast.length_long). Show ();
}
});

}
If you need to consider a better experience, you can do so
@Override
protected void OnStart () {
Super.onstart ();
LOG.I ("--", "OnStart");
Banner.isautoplay (TRUE);
}

@Override
protected void OnStop () {
Super.onstop ();
LOG.I ("--", "onStop");
Banner.isautoplay (FALSE);
}
}

Layout interface Activity_main.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout 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:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
Tools:context= "Com.example.carson_ho.android_banner. Mainactivity ">

<com.youth.banner.banner
xmlns:app= "Http://schemas.android.com/apk/res-auto"
Android:id= "@+id/banner"
Android:layout_width= "Match_parent"
android:layout_height= "300DP"/>
</RelativeLayout>

App/build.gradle file Additions
Compile ' com.youth.banner:banner:1.1.5 '

"Androidmanifest.xml" list file network request add permission
<uses-permission android:name= "Android.permission.INTERNET"/>


Android Carousel Diagram

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.