Open zpszz opened 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"
加一行这个就行
项目一些版本配置如下