根据 Liang_WK 改编,原文地址(http://m.blog.csdn.net/Liang_WK/article/details/77961720)
1,引用步骤:
(1)::在As中导入compile 'com.bigkoo:convenientbanner:2.0.5'
(2):在XML中引用
<com.bigkoo.convenientbanner.ConvenientBanner
android:layout_below="@+id/fragment_fome_header"
android:id="@+id/id_banner"
android:layout_width="match_parent"
android:layout_height="200dp"
/>
(3):引用下面网络加载的工具类
public class NetworkImageHolderView implements Holder<String> {
private ImageView imageView;
@Override
public View createView(Context context) {
//你可以通过layout文件来创建,也可以像我一样用代码创建,不一定是Image,任何控件都可以进行翻页
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
return imageView;
}
@Override
public void UpdateUI(Context context,int position, String data) {
imageView.setImageResource(R.drawable.ic_default_adimage);
ImageLoader.getInstance().displayImage(data,imageView);
}
}
(4):最后一步,给控件绑定数据
private String[] images = {"http://img2.imgtn.bdimg.com/it/u=3093785514,1341050958&fm=21&gp=0.jpg",
"http://img2.3lian.com/2014/f2/37/d/40.jpg",
"http://d.3987.com/sqmy_131219/001.jpg",
"http://img2.3lian.com/2014/f2/37/d/39.jpg",
"http://www.8kmm.com/UploadFiles/2012/8/201208140920132659.jpg",
"http://f.hiphotos.baidu.com/image/h%3D200/sign=1478eb74d5a20cf45990f9df460b4b0c/d058ccbf6c81800a5422e5fdb43533fa838b4779.jpg",
"http://f.hiphotos.baidu.com/image/pic/item/09fa513d269759ee50f1971ab6fb43166c22dfba.jpg"
};
private List<String> networkImages;
networkImages= Arrays.asList(images);
convenientBanner.setPages(new CBViewHolderCreator<NetworkImageHolderView>() {
@Override
public NetworkImageHolderView createHolder() {
return new NetworkImageHolderView();
}
},networkImages)
.setPageIndicator(new int[]{R.drawable.ponit_normal, R.drawable.point_select}) //设置两个点作为指示器
.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL); //设置指示器的方向水平居中*/