Android 超簡單自動無限輪播圖LoopView

來源:互聯網
上載者:User

標籤:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.