我尝试在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>
Run Code Online (Sandbox Code Playgroud)
我的自定义列表项:
<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>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如何在列表项之间建立间距?
我需要添加添加具有复杂项目背景的ListView:顶部和底部的偶数/奇数和圆角不同.它看起来像这样:

我已经通过level-list实现了所有这些东西,但还有一件事我想做.现在底部项目靠近屏幕的底部.最好添加一些空间.

我不想为ListView添加底部边距,我只需要最后一项的保证金.
我看到这样做的方式:
一种破解 - 将带有空TextView的页脚添加到ListView.但是页脚是非常不稳定的东西,它们通常会在notifyDataSetChanged之后消失,并且无法让它们恢复
我让设计师向底部背景资源添加透明像素.不幸的是,在这种情况下,垂直居中完全被打破.例如,有9patch像这样:

和这样的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- View with background with transparent pixels on bottom -->
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/item"
android:background="@drawable/some_bgr"
android:padding="10dp"
>
<TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"
android:text="Title"
android:layout_gravity="center"
android:textSize="18sp"
/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Detail"
android:layout_gravity="center"
android:textSize="18sp"
/>
</LinearLayout>
<!-- Just for marking place took by view -->
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_below="@id/item"
android:background="#88ff55"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
结果:

如您所见,居中不起作用.不幸.(顺便说一句,如果将此9patch指定为TextView的背景,则居中工作效果很好.如果你知道任何文章,请解释一下,请告诉我.)
这应该工作,但由于未知的原因,我仍然无法使它工作.我不喜欢这种方式,因为我不喜欢修改代码中的维度.
已经存在想象的方式 - 使用特定的位图和边距构造一些XML drawable.根据drawables概念应该是可能的,但我找不到实现.可能有人知道吗?
还有其他想法吗?
我有一个ListView,里面有很多项目.如何使顶部项目的顶部和底部项目的上边距为10dp,底部项目的下边距为10dp?现在我可以使用ListView上的填充或边距来执行此操作,但结果是当您滚动ListView的边缘时,现在距屏幕底部10dp.无论如何围绕这个?我也尝试在我的适配器的getView方法中设置边距但我没有看到AbsListView.LayoutParams的任何边距选项.任何帮助都会很棒.
谢谢
设置时
android:clipToPadding="false"
Run Code Online (Sandbox Code Playgroud)
在2.3.3安卓设备上的标准ListView中,我看到列表项目过早被回收.适配器的视图在完全滚动到填充之后被移除而不是滚动超过屏幕边缘导致视图被过早删除.有没有人能够解决这个问题?