Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在listview的行之间留出空白?_Android - Fatal编程技术网

Android 如何在listview的行之间留出空白?

Android 如何在listview的行之间留出空白?,android,Android,在我的应用程序中,我要求listview在列表行之间留有空格,这样我就可以为每一行提供背景,它看起来就像是一块块的行 我尽了最大努力,但没有找到任何解决办法。您可以使用android:divider和android:dividerHeight自定义行间距 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" andr

在我的应用程序中,我要求listview在列表行之间留有空格,这样我就可以为每一行提供背景,它看起来就像是一块块的行


我尽了最大努力,但没有找到任何解决办法。

您可以使用
android:divider
android: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>

我也有同样的问题,只是我需要通过编程设置分隔符,因为视图是动态生成的。我之所以发布这个答案,是因为这是我第一次在谷歌上大放异彩,以备将来参考。

您需要一个自定义的
可绘制的

使用以下代码创建新文件:
drawable/list\u 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>

结果完全一样。

你能给演示图像显示你真正想要的吗???。请附上一些演示/示例图像以显示你真正想要的…你可以设置填充(视图的一部分)和边距(视图的一部分除外,因此将获得ListView背景)对于listview中的每个视图,我使用pulltorefresh listview api获取android中facebook应用程序的功能。我正在开发与facebook应用程序功能相同的应用程序。请帮助我解决此问题。我正在开发具有facebook功能的应用程序。在我的一个屏幕上,我需要显示用户的新闻提要。我正在开发一个具有facebook功能的应用程序。在我的一个屏幕中,我需要显示用户的新闻源。在facebook应用程序中,我们发现列表看起来像一排排。我只想将该功能赋予我的屏幕。我使用的是pulltorefresh listview概念。
listView.setDivider(getResources().getDrawable(R.drawable.list_divider));