RecyclerView item獨佔一行實現

核心代碼:ide

GridLayoutManager manager = new GridLayoutManager(context, 4);
        manager.setSpanSizeLookup()

 

 

  class SpanSizeLoop(var imageAdapter: MainListAdapter?,var spanCount: Int) : GridLayoutManager.SpanSizeLookup() {
        override fun getSpanSize(position: Int): Int {
            Logger.e("getSpanSize........${position}")
            return if (imageAdapter?.getItem(position)?.itemTypes == 1) spanCount else 1
        }
    }

 

recycler.run {
            var llManager = GridLayoutManager(SampleApplicationLike.context,SPAN_COUNT,RecyclerView.VERTICAL,false)
            imageAdapter = MainListAdapter(SampleApplicationLike.context,getTestData(),calcImageWidth())
            adapter = imageAdapter
            // 須要先設置adapter
            llManager.spanSizeLookup = SpanSizeLoop(imageAdapter,SPAN_COUNT)
            layoutManager = llManager
            addItemDecoration(RecyclerViewGridItemDecoration(dividerWidth,Color.WHITE,RecyclerView.VERTICAL))
            adapter?.notifyDataSetChanged()
        }

 

相關文章
相關標籤/搜索