【问题标题】:Remove left space between ListView border and Items删除 ListView 边框和 Items 之间的剩余空间
【发布时间】:2017-10-05 05:38:58
【问题描述】:

谁能告诉我如何删除列表视图边框和列表视图内的项目之间的空间?

【问题讨论】:

  • 请提供minimal reproducible example。这将包括您正在使用的具有ListView 和行的布局。或者,使用 Android Studio 中的 Layout Inspector 尝试确定您的填充或边距来自何处。

标签: android listview


【解决方案1】:

从您的 xml 列表视图布局中删除边距。

【讨论】:

    【解决方案2】:

    如果我正确理解您的问题,您不是在寻找删除列表视图边框和项目之间的空间(图像上的红色标志表示!您想删除 1 个项目内的两个元素之间的空间)。如果这是真的,那么您必须转到您创建的自定义布局文件以设置为列表视图的行。看起来你那里有 2 个 TextView(“Go”和“Bro1,Bro2 ......”)。在那里,您必须使用这 2 个文本视图的 Margin-Up 和 Margin-Bottom。

    android:layout_marginBottom="1dp"
    android:layout_marginUp="1dp"
    

    如果您指的是列表视图周围的空间,请检查列表视图的边距或列表视图父布局的填充。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="0dp">        
    
        <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"    
           android:orientation="vertical" 
           android:padding="0dp">
    
           <ListView
              android:id="@android:id/list"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_margin="0dp" />
    
        </LinearLayout>
    
    </RelativeLayout>
    

    【讨论】: