Java 如何在列表视图中添加每个项目之间的间距
我刚刚创建了一个简单的自定义列表视图,我想在列表视图中的每个项目之间添加间距我已经添加了垂直间距属性,但还没有间距这是我的列表视图xml文件Java 如何在列表视图中添加每个项目之间的间距,java,android,Java,Android,我刚刚创建了一个简单的自定义列表视图,我想在列表视图中的每个项目之间添加间距我已经添加了垂直间距属性,但还没有间距这是我的列表视图xml文件 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:l
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="abtech.waiteriano.com.waitrer.fragments.LVMenuFragment">
<!-- TODO: Update blank fragment layout -->
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:verticalSpacing="20dp"
android:layout_height="fill_parent" >
</ListView>
</FrameLayout>
这是listitem.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/menuRL"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:background="@drawable/listviewborder">
<ImageView
android:id="@+id/itemImage"
android:layout_width="65dp"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
app:srcCompat="@drawable/icic" />
<TextView
android:id="@+id/menulistTV2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/itemImage"
android:text="TextView"
android:textSize="16dp"
android:textStyle="bold" />
<RelativeLayout
android:id="@+id/qtyID"
android:layout_width="75dp"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/minusBtn"
android:background="@drawable/qty_border">
<TextView
android:id="@+id/txtQTY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="0"
android:textSize="30dp" />
</RelativeLayout>
<Button
android:id="@+id/minusBtn"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="@drawable/minus_borders"
android:text="-"
android:textSize="40dp" />
</RelativeLayout>
</LinearLayout>
只需使用:
android:divider="@android:color/transparent"
android:dividerHeight="20dp"
在ListView中
找到解决办法
在列表项中添加边距
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<TextView/>
<TextView/>
</LinearLayout>
对于第一个和最后一个项目,在Listview中添加边距
<Listview
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
在列表项中添加matginTop和marginBottom。@Rajasekhar非常感谢,请发布您的答案进行检查并打分,我将尝试此操作附加您的屏幕截图,你现在得到的。@Dev.7arooneyIt使用边距底部效果很好,我现在要附加一个图像@Radheydo你真的认为它会给出listview项目之间的间距,仅仅是因为分隔符的高度@Nabilit是补丁:是的,它将给出listview项之间的间距,这仅仅是因为分隔符的高度