youth5201314 / banner

🔥🔥🔥Banner 2.0 来了!Android广告图片轮播控件,内部基于ViewPager2实现,Indicator和UI都可以自定义。
Apache License 2.0
12.9k stars 2.51k forks source link

2.2.3版本改了什么地方啊,一样的代码,使用2.2.3版本加载不出图片,发现是onCreateHolder都没调用,但是改用2.2.2就行 #1238

Open zpszz opened 2 months ago

zpszz commented 2 months ago
class HomeBannerAdapter(dataList: ArrayList<BannerData>): BannerAdapter<BannerData, HomeBannerAdapter.BannerViewHolder>(dataList){

    inner class BannerViewHolder(var imageView: ImageView): RecyclerView.ViewHolder(imageView)

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent?.context)
        // 必须设置为match_parent,这是ViewPager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT,
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(imageView)
    }

    override fun onBindView(
        holder: BannerViewHolder,
        data: BannerData,
        position: Int,
        size: Int
    ) {
        LogUtil.d("HomeBannerAdapter", data.pic)
        holder.imageView.apply {
            LogUtil.d("HomeBannerAdapter", data.pic)
            load(data.pic)
            // 点击跳转
        }
    }
}
banner.apply {
                setAdapter(mBannerAdapter)
                indicator = CircleIndicator(context)
                addBannerLifecycleObserver(viewLifecycleOwner)
            }

项目一些版本配置如下

compileSdk = "34"
targetSdk = "34"
minSdk = "29"
versionCode = "1"
versionName = "1.0"
java = "VERSION_17"
ksp = "1.9.22-1.0.17"
agp = "8.5.1"
kotlin = "1.9.22"
wangjingchun commented 2 months ago
QQ20240829-165047@2x

加一行这个就行