Padding of grid in GridView

29,151

try it

 <?xml version="1.0" encoding="utf-8"?>
    <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/menu_category"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:columnWidth="90dp"
        android:numColumns="auto_fit"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:stretchMode="columnWidth"
        android:gravity="center"
    />

for information

http://developer.android.com/guide/topics/ui/layout/gridview.html

Share:
29,151

Related videos on Youtube

alwx
Author by

alwx

Programmer for Android platform from Russia. Software developer in e-Legion Ltd. (http://www.e-legion.com/)

Updated on June 26, 2020

Comments

  • alwx
    alwx almost 4 years

    I have some problems with my grid layout.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:id="@+id/frag_books_grid_view_layout"
         android:orientation="vertical">
            <GridView
                android:padding="0dp"
                android:cacheColorHint="@color/bg_default"
                android:listSelector="@drawable/list_selector_background"
                android:id="@+id/frag_books_grid_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:stretchMode="spacingWidth"
                android:scrollbars="none"/>
    </LinearLayout>
    

    Single item:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ListView
            android:cacheColorHint="@color/bg_default"
            android:scrollbars="none"
            android:listSelector="@drawable/list_selector_background"
            android:layout_gravity="center_vertical|left"
            android:gravity="center_vertical|left"
            android:paddingLeft="15dp"
            android:paddingRight="15dp" 
            android:id="@+id/frag_book_list_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:verticalSpacing="5dp"/>
    </LinearLayout>    
    

    Problem is that there is no left and right padding of single item. And it looks terrible when item is selected: http://i.imgur.com/rirNP.png

    Please, help to fix it.

Related