I have a ListView in my Layout.
我的布局中有一个ListView。
<ListView
android:id="@+id/list_infoitems"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
Every list item layout looks like:
每个列表项布局如下所示:
<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>
I want to have a distance between all item. For that I'v played with android:margin property, but without success.
我希望所有项目之间有距离。为此,我玩了android:margin属性,但没有成功。
Does anybody know, how to change the distance between item in a listview.
有谁知道,如何更改列表视图中的项目之间的距离。
Thank you,
谢谢,
Mur
穆尔
4 个解决方案
#1
29
You could always set the dividerHeight property. Android Docs
您始终可以设置dividerHeight属性。 Android文档
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="5dp"
/>
If that isn't what you want to do, in your listview item you could wrap your LinearLayout in a RelativeLayout and add a margin to the LinearLayout
如果这不是你想要做的,你可以在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>
#2
1
I have found that the ListView divider has fragmentation issues. In 2.3 devices, a grey line is implemented by default that doesn't show up on 4.x devices. This can be addressed by manually setting android:divider="some_value"
. I tend to handle all ListView item layout issues within the items layouts themselves. Its a dirty little trick, but resolves cross version issues. Note the addition of a "hidden" view below. This not only fixes the problem between items, but gives you equal padding after the last item in your list.
我发现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>
#3
0
Use padding or Margin or the ListView itself.
使用填充或边距或ListView本身。
<ListView
android:id="@+id/list_infoitems"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5px"
/>
#4
0
To encrease the distance between the items them self you can use
为了增加他们自己可以使用的物品之间的距离
android:dividerHeight="xxdpi"
In
在
<ListView
android:id="@+id/list_infoitems"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="xxdpi"/>
Regarts, Marco
Regarts,Marco
#1
29
You could always set the dividerHeight property. Android Docs
您始终可以设置dividerHeight属性。 Android文档
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="5dp"
/>
If that isn't what you want to do, in your listview item you could wrap your LinearLayout in a RelativeLayout and add a margin to the LinearLayout
如果这不是你想要做的,你可以在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>
#2
1
I have found that the ListView divider has fragmentation issues. In 2.3 devices, a grey line is implemented by default that doesn't show up on 4.x devices. This can be addressed by manually setting android:divider="some_value"
. I tend to handle all ListView item layout issues within the items layouts themselves. Its a dirty little trick, but resolves cross version issues. Note the addition of a "hidden" view below. This not only fixes the problem between items, but gives you equal padding after the last item in your list.
我发现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>
#3
0
Use padding or Margin or the ListView itself.
使用填充或边距或ListView本身。
<ListView
android:id="@+id/list_infoitems"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5px"
/>
#4
0
To encrease the distance between the items them self you can use
为了增加他们自己可以使用的物品之间的距离
android:dividerHeight="xxdpi"
In
在
<ListView
android:id="@+id/list_infoitems"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="xxdpi"/>
Regarts, Marco
Regarts,Marco