1.首先添加依赖
compile 'com.recker.flybanner:flybanner:1.3'
2.xml布局
<com.recker.flybanner.FlyBanner
android:id="@+id/banner_1"
android:layout_width="match_parent"
android:layout_height="200dp"/>
3.下面这是本地图片
private void initLocalBanner() {
mBannerLocal = (FlyBanner) findViewById(R.id.banner_1);
List<Integer> images = new ArrayList<>();
images.add(R.drawable.img_1);
images.add(R.drawable.img_2);
images.add(R.drawable.img_3);
images.add(R.drawable.img_4);
mBannerLocal.setImages(images);
mBannerLocal.setOnItemClickListener(new FlyBanner.OnItemClickListener() {
@Override
public void onItemClick(int position) {
toast("点击了第"+position+"张图片");
}
});
}
4.加载网络图片
private void initNetBanner() {
mBannerNet = (FlyBanner) findViewById(R.id.banner_2);
List<String> imgesUrl = new ArrayList<>();
for (int i = 0; i < mImagesUrl.length; i++) {
imgesUrl.add(mImagesUrl[i]);
}
mBannerNet.setImagesUrl(imgesUrl);
mBannerNet.setOnItemClickListener(new FlyBanner.OnItemClickListener() {
@Override
public void onItemClick(int position) {
toast("点击了第" + position + "张图片");
}
});
}