Нужен похожий дизайн

Текущий выход

Код декларации RecyclerView
Код: Выделить всё
val layoutManager: RecyclerView.LayoutManager =
GridLayoutManager(requireContext(), 2, GridLayoutManager.HORIZONTAL, false)
binding.rvStoreTypesHome.setLayoutManager(layoutManager)
binding.rvStoreTypesHome.adapter = StoreTypesAdapter(requireContext())
Код: Выделить всё
class StoreTypesAdapter(val context: Context) :
RecyclerView.Adapter() {
var width = 0
init {
width = context.getDeviceWidth()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding =
StoreTypesAdapterBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return ViewHolder(binding)
}
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val layoutParams = holder.binding.conSTAdapter.layoutParams
layoutParams.width = if (holder.adapterPosition % 2 == 0) {
(width / 2.5).toInt()
} else {
(width / 3.5).toInt()
}
layoutParams.height = ConstraintLayout.LayoutParams.WRAP_CONTENT
holder.binding.conSTAdapter.layoutParams = layoutParams
holder.binding.tvStoreNameSTAdapter.text = "Store Name $position"
}
override fun getItemCount(): Int {
return 10
}
inner class ViewHolder(var binding: StoreTypesAdapterBinding) :
RecyclerView.ViewHolder(binding.root)
}
позиции. Текст 0,1,2 — это позиция, в которую я попадаю
Код: Выделить всё
onBindViewHolderПодробнее здесь: https://stackoverflow.com/questions/785 ... rent-width
Мобильная версия