Android 中Banner的使用详解
程序员文章站
2022-06-19 22:37:24
首先倒入一个依赖: compile 'com.youth.banner:banner:1.4.9'
添加的权限:
首先倒入一个依赖: compile 'com.youth.banner:banner:1.4.9'
添加的权限:
<uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" />
布局文件:
<com.youth.banner.banner android:id="@+id/banner_id" android:layout_width="match_parent" android:layout_height="170dp"></com.youth.banner.banner>
在mainactivity中写入的代码
string url1 = "http://api.kkmh.com/v1/topic_new/discovery_list?gender=0&sa_event=eyjwcm9qzwn0ijoia3vhawthbl9hchailcj0aw1lijoxndg3odm5mdm5mze1lcjwcm9wzxj0awvzijp7ikhvbwvwywdlvgfitmftzsi6iuedremxqcisilzdb21tdw5pdhluywjoyw1lijoi54ot6zeoiiwijg9zx3zlcnnpb24ioii0ljiumiisikdlbmrlclr5cguioillpbpniygilcjgcm9trmluzenhdgvnb3j5vgfitmftzsi6iuwfqomdqcisiklzqxv0b0xvywqiomzhbhnllcikbglix3zlcnnpb24ioiixljyumzqilcikbmv0d29ya190exblijoiv0lgssisiir3awzpijp0cnvllcikbwfudwzhy3r1cmvyijoic2ftc3vuzyisikzyb21gaw5kvgfitmftzsi6iuaoqoinkcisiirzy3jlzw5fagvpz2h0ijo1nzysiknhdgvnb3j5ijoi5peg5rov6i635y-wiiwisg9tzxbhz2vvcgrhdgveyxrlijowlcjqcm9wzxj0euv2zw50ijoiumvhzezpbmrqywdliiwirmluzfrhyk5hbwuioilmjqjojzailcjhynrlc3rfz3jvdxaiojq2lcikc2nyzwvux3dpzhroijoxmdi0lcjgaw5kq2f0zwdvcnluywjoyw1lijoi5ywo6yooiiwijg9zijoiqw5kcm9pzcisilryawdnzxjqywdlijoisg9tzvbhz2uilciky2fycmllcii6iknnq0milcikbw9kzwwioijhvc1qntixmcisiirhchbfdmvyc2lvbii6ijmuoc4xin0sinr5cguioij0cmfjayisimrpc3rpbmn0x2lkijoiqto5mduxmdqynzyznzu1mta5iiwib3jpz2luywxfawqioijbojkwntewndi3njm3ntuxmdkilcjldmvudci6iljlywrgaw5kugfnzsj9"; requestparams params1 = new requestparams(); params1.seturi(url1); x.http().get(params1, new callback.commoncallback<string>() { @override public void onsuccess(final string result) { if (result != null) { gson gson = new gson(); lunboimage lunboimage = gson.fromjson(result, lunboimage.class); images = new arraylist<>(); list<lunboimage.databean.infosbean> infos = lunboimage.getdata().getinfos(); for (lunboimage.databean.infosbean bean : infos) { list<lunboimage.databean.infosbean.bannersbean> banners = bean.getbanners(); for (lunboimage.databean.infosbean.bannersbean ban : banners) { string pic = ban.getpic(); images.add(pic); } } //设置banner样式 // banner.setbannerstyle(bannerconfig.num_indicator); //设置图片的加载器 banner.setimageloader(new gliderimageloader()); banner.setdelaytime(2000); //设置图片集合 banner.setimages(images); //banner设置方法全部调用完毕时最后调用 banner.isautoplay(true); banner.start(); } } @override public void onerror(throwable ex, boolean isoncallback) { } @override public void oncancelled(cancelledexception cex) { } @override public void onfinished() { } });
以上所述是小编给大家介绍的android 中banner的使用详解,希望对大家有所帮助
下一篇: Android中banner的使用步骤