標籤:
Android 超簡單自動無限輪播圖LoopView
只需要你傳入資料就可以了
demo地址 https://github.com/wanghao200906/Android-LoopView
效果實現
1.添加依賴庫
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<ItemsEntity> 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
本片文章只為做技術收藏以及給朋友們分享一些好的代碼
Android 超簡單自動無限輪播圖LoopView