当前位置:网站首页>使用开源项目【Banner】实现轮播图效果(带小圆点)
使用开源项目【Banner】实现轮播图效果(带小圆点)
2022-07-02 02:20:00 【Rannki】
banner开源项目地址:GitHub - youth5201314/banner: Banner 2.0 来了!Android广告图片轮播控件,内部基于ViewPager2实现,Indicator和UI都可以自定义。
添加网路访问权限:
<uses-permission android:name="android.permission.INTERNET" />
在【Android Manifest.xml】中的【application】加入【android:usesCleartextTraffic="true"】使用明文网络请求,否则就要把http访问改成https访问。API级别28或更高级别的应用默认为“ false”,false标识拒绝应用使用明文网络请求的意思。
添加依赖:
implementation 'io.github.youth5201314:banner:2.2.2' // banner依赖 implementation 'com.github.bumptech.glide:glide:4.12.0' //glide加载网络图片依赖
布局文件中加入:
<com.youth.banner.Banner android:id="@+id/banner" android:layout_width="match_parent" android:layout_height="300dp" app:layout_constraintBottom_toTopOf="@+id/btn" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/>
MainActivity中加入:
List<String> bannerList = new ArrayList<>(); bannerList.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic21363tj30ci08ct96.jpg"); bannerList.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic259ohaj30ci08c74r.jpg"); bannerList.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic2b16zuj30ci08cwf4.jpg"); bannerList.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic2e7vsaj30ci08cglz.jpg"); Banner banner = findViewById(R.id.banner); banner.setAdapter(new BannerImageAdapter<String>(bannerList) { @Override public void onBindView(BannerImageHolder holder, String data, int position, int size) { Glide.with(holder.itemView) .load(data) .apply(RequestOptions.bitmapTransform(new RoundedCorners(30))) .into(holder.imageView); } }).addBannerLifecycleObserver(this).setBannerRound(30).setIndicator(new CircleIndicator(this));
打开应用即可看到,轮播图实现了,还自带了小圆点。
边栏推荐
- Pytest testing framework
- leetcode2312. 卖木头块(困难,周赛)
- 2022 Q2 - résumé des compétences pour améliorer les compétences
- leetcode2311. Longest binary subsequence less than or equal to K (medium, weekly)
- C return multiple values getter setter queries the database and adds the list return value to the window
- The basic steps of using information theory to deal with scientific problems are
- [graduation season] graduate seniors share how to make undergraduate more meaningful
- Regular expression learning notes
- Kibana操控ES
- SQL server calculates the daily average and annual average of the whole province
猜你喜欢
Leetcode face T10 (1-9) array, ByteDance interview sharing
花一个星期时间呕心沥血整理出高频软件测试/自动化测试面试题和答案
[learn C and fly] 1day Chapter 2 (exercise 2.2 find the temperature of Fahrenheit corresponding to 100 ° f)
[question] - why is optical flow not good for static scenes
No programming code technology! Four step easy flower store applet
Opengauss database backup and recovery guide
leetcode2312. 卖木头块(困难,周赛)
MySQL operates the database through the CMD command line, and the image cannot be found during the real machine debugging of fluent
Infix expression to suffix expression (computer) code
How does MySQL solve the problem of not releasing space after deleting a large amount of data
随机推荐
研发中台拆分过程的一些心得总结
Leetcode face T10 (1-9) array, ByteDance interview sharing
剑指 Offer II 031. 最近最少使用缓存
* and & symbols in C language
Es interview questions
Iterative unified writing method of binary tree
Pat a-1165 block reversing (25 points)
C write TXT file
How to hide the scroll bar of scroll view in uniapp
An analysis of circuit for quick understanding
[learn C and fly] 4day Chapter 2 program in C language (exercise 2.5 generate power table and factorial table
【带你学c带你飞】4day第2章 用C语言编写程序(练习 2.5 生成乘方表与阶乘表
Types of exhibition items available in the multimedia interactive exhibition hall
Medical management system (C language course for freshmen)
Open那啥的搭建文档
The basic steps of using information theory to deal with scientific problems are
LFM signal denoising, time-frequency analysis, filtering
CSDN article underlined, font color changed, picture centered, 1 second to understand
Comparative analysis of MVC, MVP and MVVM, source code analysis
leetcode2305. 公平分发饼干(中等,周赛,状压dp)