How to give empty space between rows of listview?

后端 未结 2 651
情歌与酒
情歌与酒 2021-01-22 10:13

In my application I have a requirement of listview with empty spaces between rows of list.So that I can give background to each row and it will look something like blocks of row

2条回答
  •  遇见更好的自我
    2021-01-22 10:49

    I had the same problem except I needed to set the divider programatically because the view was dynamically generated. I'm posting this answer because it was my first google hit for future reference.

    You need a custom Drawable.
    Create a new file with the following code:
    drawable/list_divider.xml

    
    
        
        
    
    

    Inside your java code you need to get a reference to your ListView and set the divider like this:

    listView.setDivider(getResources().getDrawable(R.drawable.list_divider));
    

    The result is exactly the same.

提交回复
热议问题