这期内容当中小编将会给大家带来有关Banner如何在Android应用中使用,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
首先倒入一个依赖: 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() { } });
上述就是小编为大家分享的Banner如何在Android应用中使用了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。