android - 具有分隔线的 ListView 项目之间的距离

标签 android android-layout android-listview margin

我有几个关于这个主题的问题,但所有这些都与 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/

相关文章:

android - 如何设置 ListView 不可点击

android - 如何取消正在进行的异步任务并在android中重新启动它

Android Imagebutton焦点发光/颜色色调

android - AppWidget 中的 GridView View 回收

android - 如何制作侧边栏菜单

Android - ListView - 默认列表项(状态)背景颜色

android-listview - `ListView` 当一些列表项的高度很大时没有滚动到准确的位置

android - 启动时未调用方法

android - 签名与未签名 apk : classDeffNotFound

android - 在 eclipse (android) 中更改附加源