我试图在listView上使用marginBottom来使listView项目之间的空间,但项目仍然附加在一起。

这可能吗?如果有,有具体的方法吗?

我的代码如下

<LinearLayout
android:id="@+id/alarm_occurences"
android:layout_width="fill_parent" 
android:orientation="vertical"
android:layout_height="fill_parent"
android:background="#EEEEFF"
xmlns:android="http://schemas.android.com/apk/res/android">

<ListView
android:id="@+id/occurences"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>

我的自定义列表项:

<com.android.alarm.listItems.AlarmListItem
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:background="@drawable/alarm_item_background"
android:layout_marginBottom="10dp"    
>
<CheckedTextView     
    android:id="@android:id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:checkMark="?android:attr/listChoiceIndicatorMultiple"
    android:textSize="20sp"
    android:textStyle="bold"
    android:typeface="serif"
    android:padding="10dp"

/>

</com.android.alarm.listItems.AlarmListItem>

在这种情况下,我如何使列表项之间的间距?


当前回答

也许你可以尝试在最外层的布局中添加android:layout_marginTop = "15dp"和android:layout_marginBottom = "15dp"

其他回答

对于我的申请,我已经这样做了

 <ListView
    android:id="@+id/staff_jobassigned_listview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="@null"
    android:dividerHeight="10dp">

</ListView>

只需要将分隔符设置为null,并为我提供高度。

例子:

android:divider="@null"

or

android:divider="@android:color/transparent"

这就是结果

也许ListView的divider或dividerHeight属性可以解决你的问题。

这将帮助您添加分隔高度。

 getListView().setDividerHeight(10)

如果你想添加一个自定义视图,你可以在listView项目布局本身中添加一个小视图。

你只需要使背景透明的列表分割线和高度根据你需要的差距。

<ListView 
         android:id="@+id/custom_list"
         android:layout_height="match_parent"
         android:layout_width="match_parent"
         android:divider="#00ffffff"
         android:dividerHeight="20dp"/>

我的解决方案是增加更多的空间,但保持水平线,在res/drawable文件夹中添加separator .xml,并在其中定义线的形状:

divider.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >

    <stroke
        android:width="1px"
        android:color="@color/nice_blue" />

</shape>

然后在我的列表中引用我的分隔符如下:

<ListView
    android:id="@+id/listViewScheduledReminders"
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_marginBottom="@dimen/mediumMargin"
    android:layout_weight="1"
    android:divider="@drawable/divider"
    android:dividerHeight="16.0dp"
    android:padding="@dimen/smallMargin" >

</ListView>

注意android:dividerHeight="16.0dp"通过增加和减少这个高度,我基本上是在分隔线的顶部和底部添加了更多的填充。

我使用这个页面作为参考:http://developer.android.com/guide/topics/resources/drawable-resource.html#stroke-element