【问题标题】:How to remove vertical space between GridView rows如何删除GridView行之间的垂直空间
【发布时间】:2021-04-24 06:00:30
【问题描述】:

我是 kotlin 的新手,我正在开发一个使用 gridview 的应用程序。我已经设法使 gridview 工作,但是我想删除每行之间的空间。我尝试将填充和垂直间距设置为 0dp,我的 listSelector 是 @null 但似乎没有任何效果。我应该怎么做才能消除行之间的垂直空间?

网格视图:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary">

    <GridView
        android:id="@+id/home_grid"
        android:numColumns="3"
        android:verticalSpacing="0dp"
        android:horizontalSpacing="0dp"
        android:background="@color/colorPrimary"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="top"
        android:stretchMode="columnWidth"
        android:listSelector="@null"
        android:gravity="center"
        android:paddingVertical="0dp"/>

</RelativeLayout>

图像视图:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary">
    
        <ImageView
            android:id="@+id/grid_image"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:adjustViewBounds="true"/>

</RelativeLayout>

【问题讨论】:

    标签: android xml kotlin gridview


    【解决方案1】:

    我认为正在发生的事情是在网格视图中添加间距以匹配父级。 将 gridview 和/或相对布局的宽度/高度更改为 wrap_content 而不是 match/fill_parent。

    API 8+ 中的 match_parent 也弃用了 fill_parent

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-01
      • 2019-10-10
      • 1970-01-01
      • 1970-01-01
      • 2013-07-01
      • 2021-03-19
      • 2017-04-17
      • 2013-07-20
      相关资源
      最近更新 更多