Android : Gridview cuts the edges of the items

I have a problem with my gridview, I don't understand why it cuts the edges of the items instead of resizing them so that they could fit . I would like to see all items entirely on every screen size. Does anyone have any idea? Thanks

Here is a XML code I used:

<GridView
    android:id="@+id/gridView"
    android:layout_width="0dp"
    android:layout_height="522dp"
    android:columnWidth="120dp"
    android:gravity="center"
    android:horizontalSpacing="0dp"
    android:numColumns="auto_fit"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/cardView2"></GridView>

item layout:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_margin="0dp"
    android:layout_gravity="center">

    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitCenter" />

</android.support.v7.widget.CardView>

looks like this

1 answer

  • answered 2018-09-24 12:24 Ali Ahmed

    Add padding to your CardView layout

    <android.support.v7.widget.CardView 
          xmlns:android="schemas.android.com/apk/res/android"; 
          android:layout_width="100dp" 
          android:layout_height="100dp" 
          android:layout_margin="0dp" 
          android:padding="11dp"
          android:layout_gravity="center"> 
    
            <ImageView 
               android:id="@+id/image" 
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:scaleType="fitCenter" /> 
    
     </android.support.v7.widget.CardView>