我有几个关于这个主题的问题,但所有这些都与 Listview items 之间的距离 相关,几乎所有答案都建议使用 Transparent Divider 作为解决方案。
但在我的例子中,我已经在两个列表项之间设置了分隔符,那么如何在两个列表项之间应用一些边距/填充/距离?
感谢任何帮助。
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>
最佳答案
基于 this tutorial ,您可以将 padding
添加到 listview_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>
关于android - 具有分隔线的 ListView 项目之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11451216/