android 自动轮播代码生成,Android 超简单自动无限轮播图LoopView

Android 超简单自动无限轮播图LoopView

只需要你传入数据就可以了

效果图

8812908f2d2b38624326081237fe778c.png

效果实现

1.添加依赖库

81c9fbc3cc879673ad036e35ccd532ec.png

2.添加到xml

<

com.kevin.loopview.AdLoopView

android:id=”@+id/main_act_adloopview”

android:layout_width=”match_parent”

android:layout_height=”540px”>

< / com.kevin.loopview.AdLoopView >

3.代码

private void initLoopView() {

final AdLoopView mLoopView = (AdLoopView) this.findViewById(R.id.main_act_adloopview);

//获取测试数据

//原作者数据来源 放在Asset中

String json = LocalFileUtils.getStringFormAsset(this, “loopview_date.json”);

//本人数据来源 使用tojson把数据变成libs库需要的格式

String json2= getLoopDataJson();

LoopData loopData = JsonTool.toBean(json, LoopData.class);

mLoopView.refreshData(loopData);

mLoopView.startAutoLoop();

mLoopView.setOnClickListener(new BaseLoopAdapter.OnItemClickListener() {

@Override

public void onItemClick(PagerAdapter parent, View view,

int position, int realPosition) {

Toast.makeText(LoopViewActivity.this, "" + position, Toast.LENGTH_SHORT).show();

}

});

}

private String getLoopDataJson() {

LoopParent mParent = new LoopParent();

List items = new ArrayList<>();

ItemsEntity itemsEntity = null;

itemsEntity = new ItemsEntity();

itemsEntity.setImgUrl("http://ww1.sinaimg.cn/large/6e0519bejw1eahallpdi5j20u00f0wip.jpg");

items.add(itemsEntity);

itemsEntity = new ItemsEntity();

itemsEntity.setDescText("只是一条测试说明");

itemsEntity.setImgUrl("http://src.house.sina.com.cn/imp/imp/deal/9e/ca/e/3e072b93e939b71274b1e3ea4cc_p7_wm43,41_mk7_c800X800.jpg");

items.add(itemsEntity);

itemsEntity = new ItemsEntity();

itemsEntity.setImgUrl("http://img0.imgtn.bdimg.com/it/u=3688416272,1545833324&fm=21&gp=0.jpg");

items.add(itemsEntity);

itemsEntity = new ItemsEntity();

itemsEntity.setImgUrl("http://src.house.sina.com.cn/imp/imp/deal/9e/ca/e/3e072b93e939b71274b1e3ea4cc_p7_wm43,41_mk7_c800X800.jpg");

items.add(itemsEntity);

mParent.setItems(items);

Log.i("TAG", new Gson().toJson(mParent));

return new Gson().toJson(mParent);

}

基本上就这样如果对显示的效果不满意可以去改改依赖库的东西

源代码地址 https://github.com/wanghao200906/Android-LoopView

本片文章只为做技术收藏以及给朋友们分享一些好的代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值