当前位置:网站首页>使用开源项目【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));打开应用即可看到,轮播图实现了,还自带了小圆点。
边栏推荐
- Summary of some experiences in the process of R & D platform splitting
- Duplicate keys detected: ‘0‘. This may cause an update error. found in
- 2022低压电工考试题模拟考试题库模拟考试平台操作
- What style of Bluetooth headset is easy to use? High quality Bluetooth headset ranking
- [learn C and fly] day 5 chapter 2 program in C language (Exercise 2)
- Infix expression to suffix expression (computer) code
- 【深度学习】infomap 人脸聚类 facecluster
- Logging only errors to the console Set system property ‘log4j2. debug‘ to sh
- Openssl3.0 learning XXI provider encoder
- Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
猜你喜欢

The concepts and differences between MySQL stored procedures and stored functions, as well as how to create them, the role of delimiter, the viewing, modification, deletion of stored procedures and fu

JPM 2021 most popular paper released (with download)

How to execute an SQL in MySQL

leetcode2311. 小于等于 K 的最长二进制子序列(中等,周赛)

From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years

MySQL如何解决delete大量数据后空间不释放的问题

How to turn off debug information in rtl8189fs

mysql列转行函数指的是什么

query词权重, 搜索词权重计算

LFM信号加噪、时频分析、滤波
随机推荐
[reading notes] programmer training manual - practical learning is the most effective (project driven)
RTL8189FS如何关闭Debug信息
Ar Augmented Reality applicable scenarios
* and & symbols in C language
Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
Spend a week painstakingly sorting out the interview questions and answers of high-frequency software testing / automated testing
【毕业季】研究生学长分享怎样让本科更有意义
A quick understanding of analog electricity
2022 Q2 - Summary of skills to improve skills
leetcode2309. The best English letters with both upper and lower case (simple, weekly)
【带你学c带你飞】3day第2章 用C语言编写程序(练习 2.3 计算分段函数)
离婚3年以发现尚未分割的共同财产,还可以要么
Opencascade7.6 compilation
Five skills of adding audio codec to embedded system
OpenCASCADE7.6编译
oracle创建只读权限的用户简单四步走
leetcode2311. 小于等于 K 的最长二进制子序列(中等,周赛)
Construction and maintenance of business websites [14]
MySQL constraints and multi table query example analysis
Opengauss database backup and recovery guide