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

epggiuax  于 4个月前  发布在  其他
关注(0)|答案(1)|浏览(118)
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"

相关问题