2012-10-27 133 views
2

在我的应用程序中,我有listview的行之间的空白空间的要求。因此,我可以给每行的背景,它会看起来像块的行。如何给列表视图的行之间的空白空间?

我尽我所能,但没有找到任何解决方案。

+3

你可以给演示图像,显示你想要什么?其实..请附上一些演示/示例图像,显示你真正想要的... –

+2

可以设置填充(视一部分)和利润(不的一部分视图,以便将得到ListView的背景),以便在ListView –

+0

可以使用自定义列表视图 –

回答

3

您可以使用android:dividerandroid:dividerHeight来自定义行之间的间距。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <ListView 
    android:id="@+id/android:list" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:divider="#FF0000" 
    android:dividerHeight="4px"/> 

</LinearLayout> 
+0

我正在开发具有facebook功能的应用程序。在我的一个屏幕上,我需要显示用户的新闻源。 – veerendra

+0

我正在开发具有facebook功能的应用程序。在我的屏幕之一,我需要为我们找到了名单看起来像rows.I块只是想我screen.I正在使用pulltorefresh列表视图的概念,得到functinality显示用户。在Facebook的应用程序的新闻源。 – veerendra

0

我有同样的问题,除了我需要以编程方式设置分频器,因为视图是动态生成的。我发布这个答案,因为这是我第一次为未来参考的谷歌命中。

您需要定制Drawable
创建一个包含以下代码的新文件:
drawable/list_divider.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 
    <size 
     android:height="16dp"/> 
    <solid android:color="@android:color/transparent"/> 
</shape> 

内,您的Java代码,你需要得到一个关于你ListView,并设置这样的除法:

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

的结果是完全一样的。