我尝试在 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 几乎一针见血,但我只是想为以后可能通过 google 漂浮在这里的任何人添加一点 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
值。它需要一个 float 和一个单位,例如“10.0sp”。正如@Goofyahead 所说,您还可以为此值使用与显示无关的像素(即“10dp”)。
关于android - 如何在Android中设置listView项目之间的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4984313/