//无限轮播的依赖
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>