RecyclerView item独占一行实现

核心代码:

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()
        }

 

posted @ 2019-08-30 16:34  疯子FK  阅读(1446)  评论(0编辑  收藏  举报