ListView divider not showing in Android 5

后端 未结 4 1153
我寻月下人不归
我寻月下人不归 2021-01-04 23:34

I have a simple listview for which I have defined a custom drawable for the divider. I have defined the divider height to be 1dp. The listview is within a fragment.

4条回答
  •  悲哀的现实
    2021-01-05 00:18

    Updated answer

    After further testing it appears that the dividers will only show if the height of the divider is strictly less than the dividerHeight set for the ListView. For instance:

    custom_divider.xml (Note that the divider height is specified by android:width)

    
        
    
    

    Layout xml

    
    

    ...Will work. But this will not:

    custom_divider.xml (Note that the divider height is specified by android:width)

    
        
    
    

    Layout xml

    
    

    My guess is that Google messed up with the optimization for drawing Listview dividers and will simply not draw them if there is not enough room.

    Original post

    Looks like you need to both set the dividerHeight on the ListView and the stroke width of the divider drawable for this to work on Android 5.

    Example:

    custom_divider.xml

    
        
    
        
    
    

    Layout xml

    
    

提交回复
热议问题