1,导入依赖
implementation 'io.github.youth5201314:banner:2.2.2'
implementation 'com.github.bumptech.glide:glide:4.13.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'
<com.youth.banner.Banner3,添加源码
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
package com.example.lunbo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.bumptech.glide.Glide;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
Banner banner;
List<String> bannerList=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
banner=findViewById(R.id.banner);
bannerList.add("https://p2.itc.cn/images01/20210510/096eeb9cd3c84bd8ba09b5713679b4f9.jpeg");
bannerList.add("https://p2.itc.cn/images01/20210510/096eeb9cd3c84bd8ba09b5713679b4f9.jpeg");
bannerList.add("http://i0.hdslb.com/bfs/article/97549c0fd58b940c1306faac923a8685551a6a2a.jpg");
banner.setAdapter(new BannerImageAdapter<String>(bannerList) {
@Override
public void onBindView(BannerImageHolder holder, String data, int position, int size) {
Glide.with(holder.imageView)
.load(data)
.into(holder.imageView);
}
});
//轮播图下面的原点
banner.setIndicator(new CircleIndicator(this));
banner.setIndicatorRadius(50);
}
}
- 本文标题: 安卓导入banner轮播图
- 文章分类:【Android】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.