无限轮播

//无限轮播的依赖

compile 'com.bigkoo:convenientbanner:2.0.5'

package com.example.myapplication;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity implements OnItemClickListener {
    private ConvenientBanner conven;

    private ArrayList<Integer> imgs= new ArrayList<Integer>();
    private String[] imags=new String[]{
            "http://image.wufazhuce.com/FvVmWbqlle7jlUCTeozoval9NyBH",
            "http://image.wufazhuce.com/FmDRnQ1XhReHRHB4jYqAPSx8htsP",
            "http://image.wufazhuce.com/Fu6o0fqKHsI_TjdpPX3N2Kc99vNP",
            "http://image.wufazhuce.com/FuPgOcbGDD9__fyuCdPBXb5pbA1C"};
    List<String> datas;
    ImageLoader imgslod;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        conven = (ConvenientBanner) findViewById(R.id.con);
        imgslod = ImageLoader.getInstance();
        imgslod.init(ImageLoaderConfiguration.createDefault(this));
        datas=Arrays.asList(imags);
        conven.setPages(new CBViewHolderCreator() {
            @Override
            public Object createHolder() {
                return new Myhoude();
            }
        },datas)
                //设置指示器是否可见
                .setPointViewVisible(true)
                //设置自动切换(同时设置了切换时间间隔)
                .startTurning(2000)
                //设置两个点图片作为翻页指示器,不设置则没有指示器,可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
                .setPageIndicator(new int[]{R.drawable.ic_page_indicator,R.drawable.ic_page_indicator_focused})
                //设置指示器的方向(左、中、右)
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
                //设置点击事件
                .setOnItemClickListener(this)
                //默认是TRUE
                .setManualPageable(true);
            }


    @Override
    public void onItemClick(int position) {

    }

    private class Myhoude 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) {
            ImageLoader.getInstance().displayImage(data,imageView);
        }
    }
    /*public int getid(String name,Class<?> c){
        Field field = null;
        try {
            field = c.getDeclaredField(name);
            return field.getInt(field);
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }*/
}

//布局

  <com.bigkoo.convenientbanner.ConvenientBanner
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:id="@+id/con"
        ></com.bigkoo.convenientbanner.ConvenientBanner>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值