How to add dividers and spaces between items in RecyclerView?

前端 未结 30 3614
清歌不尽
清歌不尽 2020-11-22 03:27

This is an example of how it could have been done previously in the ListView class, using the divider and dividerHeight parame

30条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 04:27

    This is simple, you don't need such complicated code

    DividerItemDecoration divider = new 
    DividerItemDecoration(mRVMovieReview.getContext(), 
    DividerItemDecoration.VERTICAL);
    divider.setDrawable(
        ContextCompat.getDrawable(getBaseContext(), R.drawable.line_divider)
    );
    mRVMovieReview.addItemDecoration(divider);
    

    Add this in your drawable : line_divider.xml

    
    
        
        
    
    

提交回复
热议问题