How to add dividers and spaces between items in RecyclerView?

前端 未结 30 3380
清歌不尽
清歌不尽 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:32

    The RecyclerView is a bit different from the ListView. Actually, the RecyclerView needs a ListView like structure in it. For example, a LinearLayout. The LinearLayout has parameters for the dividing each element. In the code below I have a RecyclerView comprised of CardView objects within a LinearLayout with a "padding" that will put some space between items. Make that space really small and you get a line.

    Here's the Recycler view in recyclerview_layout.xml

    
    
        
        
    
    
    

    And here is what each item looks like (and it shows as divided due to the android:padding in the LinearLayout that surrounds everything.) in another file: cards_layout.xml

    
    
        
        
                
        
    
    

提交回复
热议问题