当前位置:网站首页>使用开源项目【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));打开应用即可看到,轮播图实现了,还自带了小圆点。
边栏推荐
- 花一个星期时间呕心沥血整理出高频软件测试/自动化测试面试题和答案
- Iterative unified writing method of binary tree
- Quality means doing it right when no one is looking
- flutter 中間一個元素,最右邊一個元素
- leetcode2305. 公平分发饼干(中等,周赛,状压dp)
- Five skills of adding audio codec to embedded system
- Construction and maintenance of business websites [11]
- Oracle creates a user with read-only permission in four simple steps
- JVM面试篇
- Which is a good Bluetooth headset of about 300? 2022 high cost performance Bluetooth headset inventory
猜你喜欢

Opencascade7.6 compilation

leetcode2312. 卖木头块(困难,周赛)

CVPR 2022 | 大连理工提出自校准照明框架,用于现实场景的微光图像增强

Redis有序集合如何使用

MySQL约束与多表查询实例分析

What are the necessary things for students to start school? Ranking list of Bluetooth headsets with good sound quality

【带你学c带你飞】3day第2章 用C语言编写程序(练习 2.3 计算分段函数)

Design and implementation of key value storage engine based on LSM tree

No programming code technology! Four step easy flower store applet

Summary of some experiences in the process of R & D platform splitting
随机推荐
Post infiltration flow encryption
Pytest testing framework
golang---锁
Es interview questions
* and & symbols in C language
What style of Bluetooth headset is easy to use? High quality Bluetooth headset ranking
剑指 Offer 47. 礼物的最大价值
[learn C and fly] 1day Chapter 2 (exercise 2.2 find the temperature of Fahrenheit corresponding to 100 ° f)
C # use system data. The split mixed mode assembly is generated for the "v2.0.50727" version of the runtime, and it cannot be loaded in the 4.0 runtime without configuring other information
Quality means doing it right when no one is looking
What are the necessary things for students to start school? Ranking list of Bluetooth headsets with good sound quality
Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
2022 Q2 - Summary of skills to improve skills
Comparative analysis of MVC, MVP and MVVM, source code analysis
C return multiple values getter setter queries the database and adds the list return value to the window
Summary of some experiences in the process of R & D platform splitting
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
Sword finger offer 42 Maximum sum of continuous subarrays
STM32F103 - two circuit PWM control motor
Build a modern data architecture on the cloud with Amazon AppFlow, Amazon lake formation and Amazon redshift