当前位置:网站首页>使用开源项目【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));打开应用即可看到,轮播图实现了,还自带了小圆点。
边栏推荐
- An analysis of circuit for quick understanding
- 【带你学c带你飞】1day 第2章 (练习2.2 求华氏温度 100°F 对应的摄氏温度
- CVPR 2022 | 大连理工提出自校准照明框架,用于现实场景的微光图像增强
- Construction and maintenance of business websites [11]
- Build a modern data architecture on the cloud with Amazon AppFlow, Amazon lake formation and Amazon redshift
- Sword finger offer 62 The last remaining number in the circle
- Word search applet design report based on cloud development +ppt+ project source code + demonstration video
- Email picture attachment
- 剑指 Offer 29. 顺时针打印矩阵
- essay structure
猜你喜欢

A quick understanding of digital electricity

Comparative analysis of MVC, MVP and MVVM, source code analysis

Build a modern data architecture on the cloud with Amazon AppFlow, Amazon lake formation and Amazon redshift
![[learn C and fly] 4day Chapter 2 program in C language (exercise 2.5 generate power table and factorial table](/img/f4/298f64c4b4f8674eda4e8fb19a976a.png)
[learn C and fly] 4day Chapter 2 program in C language (exercise 2.5 generate power table and factorial table

剑指 Offer 62. 圆圈中最后剩下的数字

An analysis of circuit for quick understanding

Leetcode face T10 (1-9) array, ByteDance interview sharing

Opengauss database backup and recovery guide
![[liuyubobobo play with leetcode algorithm interview] [00] Course Overview](/img/1c/c8cab92c74b6658c3ef608c5255f1f.png)
[liuyubobobo play with leetcode algorithm interview] [00] Course Overview

JVM interview
随机推荐
[reading notes] programmer training manual - practical learning is the most effective (project driven)
From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years
A quick understanding of analog electricity
[learn C and fly] 4day Chapter 2 program in C language (exercise 2.5 generate power table and factorial table
[question] - why is optical flow not good for static scenes
No programming code technology! Four step easy flower store applet
What is the MySQL column to row function
Architecture evolution from MVC to DDD
【带你学c带你飞】3day第2章 用C语言编写程序(练习 2.3 计算分段函数)
Architecture evolution from MVC to DDD
花一个星期时间呕心沥血整理出高频软件测试/自动化测试面试题和答案
[technology development -21]: rapid overview of the application and development of network and communication technology -1- Internet Network Technology
leetcode2310. 个位数字为 K 的整数之和(中等,周赛)
大厂裁员潮不断,双非本科出身的我却逆风翻盘挺进阿里
Exception handling of class C in yyds dry goods inventory
MySQL constraints and multi table query example analysis
How to execute an SQL in MySQL
Which is a good Bluetooth headset of about 300? 2022 high cost performance Bluetooth headset inventory
query词权重, 搜索词权重计算
C return multiple values getter setter queries the database and adds the list return value to the window