3

我在这个主题上有几个关于 SO 的问题,但所有这些问题都与Listview 项目之间的距离有关,几乎所有答案都建议使用透明分隔线作为解决方案。

但就我而言,我已经在两个列表项之间设置了分隔符,那么如何在两个列表项之间应用一些边距/填充/距离?

任何帮助表示赞赏。

xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listMainPlans"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@drawable/list_divide"
        android:dividerHeight="2dp" >
    </ListView>

</LinearLayout>
4

2 回答 2

4

根据本教程,您可以添加paddinglistview_item_row.xml

ListView使用您的适配器,您可以为您(教程中的WeatherAdapter.java)中的每个元素扩展此xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"> // <-----

     <ImageView  />

     <TextView  />

</LinearLayout>
于 2012-07-12T12:03:20.023 回答
1

为该相对布局提供静态高度,例如:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_innerbg">

    <RelativeLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/item_background"
        android:minHeight="40dp">

    <TextView 
        android:id="@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16dp"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:textColor="@color/blue"
        android:layout_marginRight="45dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:textStyle="bold"/>



    <TextView 
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:layout_alignParentRight="true"
         android:layout_centerInParent="true"
         android:layout_marginRight="10dp"/>

    </RelativeLayout>

</RelativeLayout>

您将获得每行项目之间的距离

于 2012-07-12T12:03:42.740 回答