ListView Items Android之间的间距

我试图在listView上使用marginBottom以在listView Item之间留出空间,但仍然将这些项目连接在一起。

它甚至有可能吗? 如果是的话,是否有具体的方法来做到这一点?

我的代码如下

<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>

在这种情况下,我如何在列表项目之间进行间隔?


@Asahi几乎击中了头部,但我只是想为以后通过谷歌在这里漂浮的任何人添加一点XML:

<ListView android:id="@+id/MyListView"
  android:layout_height="match_parent"
  android:layout_width="match_parent"
  android:divider="@android:color/transparent"
  android:dividerHeight="10.0sp"/>

出于某种原因,诸如“10”,“10.0”和“10sp”等值都会被Android拒绝dividerHeight值。 它需要一个浮点数和一个单位,比如“10.0sp”。 正如@Goofyahead所指出的那样,您也可以为此值使用与显示无关的像素(即“10dp”)。


或许ListView dividerdividerHeight属性可以解决您的问题。


尽管Nik Reiman的解决方案能够发挥作用,但我发现它并不是我想要做的最佳解决方案。 使用分隔线来设置页边距会产生分隔线不再可见的问题,因此您无法使用它来显示您的项目之间清晰的边界。 此外,它不会为每个项目添加更多的“可点击区域”,因此如果您想让您的项目可点击并且您的项目很薄,任何人都很难点击某个项目,因为分隔线添加的高度不是项目的一部分。

幸运的是,我发现了一个更好的解决方案,可以让您显示分隔线,并且可以使用不是边距而是填充来调整每个项目的高度。 这里是一个例子:

列表显示

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

项目清单

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="10dp"
    android:paddingTop="10dp" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Item"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>
链接地址: http://www.djcxy.com/p/93265.html

上一篇: Spacing between listView Items Android

下一篇: Web colors in an Android color xml resource file