Banner下面的红色进度条
2020-07-15 本文已影响0人
小赵不在
微信图片_20200715165654.png
1、布局(必须要用线性布局)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.youth.banner.Banner
android:id="@+id/banner_recommend"
android:layout_width="match_parent"
android:layout_height="180dp" />
<ProgressBar
android:id="@+id/pb"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
2、适配器代码
if (itemViewType == VIEW_TYPE_ONE) {
ArrayList<String> images = new ArrayList<>();
ArrayList<String> titles = new ArrayList<>();
for (int i = 0; i < bannerListBeans.size(); i++) {
images.add(bannerListBeans.get(i).getImage_url());
titles.add(bannerListBeans.get(i).getTheme());
}
ViewHolder viewHolder = (ViewHolder) holder;
viewHolder.pb.setMax(4);//进度为4
viewHolder.pb.setProgress(1);//从1开始
viewHolder.banner_recommend.setImages(images)
.setBannerTitles(titles)
.setBannerStyle(BannerConfig.NUM_INDICATOR_TITLE)
.setImageLoader(new ImageLoader() {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
Glide.with(context).load(path).into(imageView);
}
})
.start()
.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
viewHolder.pb.setProgress(position + 1);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});