Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.8k views
in Technique[技术] by (71.8m points)

android - How to remove vertical space between GridView rows

I'm new to kotlin and I am developing an app that uses a gridview. I've managed to make the gridview work, however I want to remove the space between each row. I've tried setting padding and vertical spacing to 0dp, my listSelector is @null but nothing seems to work. What should I do to remove the vertical space between rows?

Grid View:


<?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>

Image View:


<?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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think what is happening is it is adding the spacing in the grid view to match the parent. Change the width/height of the gridview and/or relative layout to wrap_content instead of match/fill_parent.

Also fill_parent has been deprecated in place for match_parent in API 8+


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...