Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Listview中项目之间的距离_Android_View_Draw - Fatal编程技术网

Android Listview中项目之间的距离

Android Listview中项目之间的距离,android,view,draw,Android,View,Draw,我的布局中有一个列表视图 <ListView android:id="@+id/list_infoitems" android:layout_width="fill_parent" android:layout_height="wrap_content"/> 每个列表项布局如下所示: <LinearLayout xmlns:android="http://schemas.android.com/apk/re

我的布局中有一个列表视图

    <ListView 
        android:id="@+id/list_infoitems"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

每个列表项布局如下所示:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@drawable/selector_custombutton"
    android:padding="10dp"
    android:layout_gravity="center">
    <TextView
        android:id="@+id/text_history_station_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|left"
        android:textColor="@color/rnv_blue_540c"/>
    <TextView
        android:id="@+id/text_history_line_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|left"
        android:textColor="@color/rnv_blue_540c"/>      
</LinearLayout>

我希望所有项目之间有一个距离。为此,我玩了安卓:保证金财产,但没有成功

有人知道如何更改listview中项目之间的距离吗

谢谢,


Mur

使用填充、边距或ListView本身

<ListView 
        android:id="@+id/list_infoitems"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5px"
/>

始终可以设置dividerHeight属性


如果您不想这样做,那么在listview项目中,您可以将LinearLayout包装在RelativeLayout中,并为LinearLayout添加边距

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
    />
</RelativeLayout>

要缩短它们自己可以使用的项目之间的距离

android:dividerHeight="xxdpi"


恢复,
Marco

我发现ListView分隔器存在碎片问题。在2.3设备中,默认情况下会实现一条灰线,该灰线不会显示在4.x设备上。这可以通过手动设置
android:divider=“some_value”
来解决。我倾向于在项目布局本身中处理所有ListView项目布局问题。这是一个肮脏的小把戏,但解决了跨版本的问题。注意下面添加了一个“隐藏”视图。这不仅解决了项目之间的问题,而且在列表中最后一个项目之后提供了相等的填充空间

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="5dp" />

    <View
        android:below="@id/list"
        android:layout_height="0dp"
        android:layout_width="0dp"
        android:margin_top="5dp" />
</RelativeLayout>


每行之间的距离?我的想法和你的第二个建议一样,但你的第一个建议对我很有帮助,而且更好:)谢谢你这对我很有用,只是我的列表是黑色的,分隔符是灰色的。确保将分隔符更改为与列表相同的颜色!android:divider=“#00000”在我的例子中。@NPike,或使用#00000000使分隔符透明
<ListView 
    android:id="@+id/list_infoitems"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:dividerHeight="xxdpi"/>
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="5dp" />

    <View
        android:below="@id/list"
        android:layout_height="0dp"
        android:layout_width="0dp"
        android:margin_top="5dp" />
</RelativeLayout>