图片无限轮播

//主代码
private void initdata() {
    convenientBanner.setPages(new CBViewHolderCreator() {
        @Override
        public Object createHolder() {
            return new LocalImageHolderView();
        }
    }, mList) //mList是图片地址的集合
            .setPointViewVisible(true)    //设置指示器是否可见
            //设置两个点图片作为翻页指示器,不设置则没有指示器,可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
            .setPageIndicator(new int[]{R.drawable.normal, R.drawable.unnormal})
            //设置指示器位置(左、中、右)
            .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
            .startTurning(2000)     //设置自动切换(同时设置了切换时间间隔)
            .setManualPageable(true);  //设置手动影响(设置了该项无法手动切换)
}


class LocalImageHolderView implements Holder<String> {

    private ImageView imageView;

    @Override
    public View createView(Context context) {
        imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        return imageView;
    }

    @Override
    public void UpdateUI(Context context, int position, String data) {
        //glide加载出图片,data是传过来的图片地址,
        ImageLoader.getInstance().displayImage(data,imageView);

    }
}
 
//布局
 
  
<com.bigkoo.convenientbanner.ConvenientBanner
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/conven"
android:layout_width="match_parent"
android:layout_height="150dp"
app:canLoop="true"/>
 
//normal
 
  
xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <solid android:color="@color/huise" />
    <corners android:radius="10dp"
        />
    <size android:height="5dp"
        android:width="5dp"/>

shape>
 
 
 
//unnormal
xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <solid android:color="@color/fense" />
    <corners android:radius="10dp" />
    <size android:height="5dp"
        android:width="5dp"/>
shape>

你可能感兴趣的:(图片无限轮播)