GridView : Removing spaces between horizontal and vertical spaces

∥☆過路亽.° 提交于 2019-12-13 05:23:32

问题


Item of the grid view

  <com.android.volley.toolbox.NetworkImageView
            android:id="@+id/iconGrid"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center_horizontal"
            android:adjustViewBounds="true"/>

Grid view layout

 <GridView
    android:id="@+id/gridView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:listSelector="#80AD3B6D"
    android:verticalSpacing="0dp"
    android:horizontalSpacing="0dp"
    android:stretchMode="columnWidth"
    android:numColumns="3">
</GridView>

For some reasons, the grid view still have spaces between them, and i'll try all the possible solution, but still unable to do it. Somehow there's a gap on each side of the image(item). And i all want is to make all the images with no space between them. i.e instagram grid view(close together)

Thank you in advance

SOLUTION

So i already figure how to change the whole thing to make it NO GAP in between. and Gridview.xml still remain the same.

This will be the items.xml :

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="wrap_content"
        android:background="#000000"
        android:layout_height="wrap_content">

        <com.android.volley.toolbox.NetworkImageView
            android:id="@+id/iconGrid"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="right|bottom"
            android:padding="2dp"
            android:orientation="horizontal">


            <ImageView
                android:id="@+id/like"
                android:layout_width="15dp"
                android:layout_height="15dp"
                android:src="@drawable/hwhite"
                android:visibility="invisible" />

            <TextView
                android:id="@+id/num"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|right"
                android:text="121"
                android:textColor="#FFFFFF"
                android:visibility="invisible" />

        </LinearLayout>
    </FrameLayout>

</LinearLayout>

回答1:


Try be removing the following attribute:

android:stretchMode="columnWidth"

This problem has been encountered there, so please give a look as well: Which stretchMode to use in GridView on android



来源:https://stackoverflow.com/questions/33602304/gridview-removing-spaces-between-horizontal-and-vertical-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!