如何在Android中的listView Items之间设置空间 [英] How to set space between listView Items in Android

查看:24
本文介绍了如何在Android中的listView Items之间设置空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 listView 上使用 marginBottom 在 listView Item 之间腾出空间,但这些项目仍然连接在一起.

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

我的代码在下面

<列表视图android:id="@+id/出现次数"android:layout_width="fill_parent"android:layout_height="fill_parent"/></LinearLayout>

我的自定义列表项:

在这种情况下,如何在列表项之间设置间距?

解决方案

@Asahi 几乎一针见血,但我只是想为任何人添加一点 XML,这些 XML 可能稍后通过 google 来到这里:

>

出于某种原因,Android 拒绝了诸如10"、10.0"和10sp"之类的 dividerHeight 值.它需要一个浮点数和一个单位,例如10.0sp".正如@Goofyahead 所指出的,您还可以为此值(即10dp")使用与显示无关的像素.

I tried to use marginBottom on the listView to make space between listView Item, but still the items are attached together.

Is it even possible? If yes, is there a specific way to do it?

My code is below

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

My custom List item:

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

How can I make spacing between list items in this case?

解决方案

@Asahi pretty much hit the nail on the head, but I just wanted to add a bit of XML for anyone maybe floating in here later via google:

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

For some reason, values such as "10", "10.0", and "10sp" all are rejected by Android for the dividerHeight value. It wants a floating point number and a unit, such as "10.0sp". As @Goofyahead notes, you can also use display-independent pixels for this value (ie, "10dp").

这篇关于如何在Android中的listView Items之间设置空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆