当前位置:网站首页>使用开源项目【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));打开应用即可看到,轮播图实现了,还自带了小圆点。
边栏推荐
- [technology development -21]: rapid overview of the application and development of network and communication technology -1- Internet Network Technology
- how to come in an investnent bank team
- C write TXT file
- Five skills of adding audio codec to embedded system
- leetcode2312. Selling wood blocks (difficult, weekly race)
- Oracle creates a user with read-only permission in four simple steps
- Construction and maintenance of business websites [12]
- Spend a week painstakingly sorting out the interview questions and answers of high-frequency software testing / automated testing
- 离婚3年以发现尚未分割的共同财产,还可以要么
- Architecture evolution from MVC to DDD
猜你喜欢

Redis有序集合如何使用

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

Deployment practice and problem solving of dash application development environment based on jupyter Lab

How to solve MySQL master-slave delay problem

附加:信息脱敏;

Query word weight, search word weight calculation

How to batch add background and transition effects to videos?

How to use redis ordered collection

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

Architecture evolution from MVC to DDD
随机推荐
[learn C and fly] day 5 chapter 2 program in C language (Exercise 2)
Quality means doing it right when no one is looking
Open that kind of construction document
How to build and use redis environment
No programming code technology! Four step easy flower store applet
How does MySQL solve the problem of not releasing space after deleting a large amount of data
剑指 Offer 47. 礼物的最大价值
essay structure
[opencv] - comprehensive examples of five image filters
SQL server calculates the daily average and annual average of the whole province
What style of Bluetooth headset is easy to use? High quality Bluetooth headset ranking
Deep learning: a solution to over fitting in deep neural networks
golang---锁
Pat a-1165 block reversing (25 points)
AR增强现实可应用的场景
大厂裁员潮不断,双非本科出身的我却逆风翻盘挺进阿里
[learn C and fly] 1day Chapter 2 (exercise 2.2 find the temperature of Fahrenheit corresponding to 100 ° f)
leetcode2311. Longest binary subsequence less than or equal to K (medium, weekly)
[graduation season] graduate seniors share how to make undergraduate more meaningful
Calculation (computer) code of suffix expression