My Recycler Item which inflate in onCreateViewHolder
kotlin version
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = ItemBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
binding.root.post {
binding.root.layoutParams.height = parent.width/3
binding.root.requestLayout()
}
return ViewHolder(binding)
}
here 3 is the span count of your GridLayoutManager
. You can replace binding.root
with your itemView
, if you are not using Databinding