25

I have this GridView (see screenshot) that contains items that all need about 12 dip spacing. However, when I set padding on the GridView, it seems that I can't scroll across this paddingm which I do want to do. How do I achieve this?

Note the slice of space above the top two pictures that I want to scroll away from:

screenshot while scrolling

Code:

<GridView
    android:id="@+id/feed_grid"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:columnWidth="96dp"
    android:gravity="center"
    android:horizontalSpacing="@dimen/grid_view_margins"
    android:numColumns="auto_fit"
    android:padding="@dimen/grid_view_margins"
    android:stretchMode="columnWidth"
    android:scrollbarStyle="outsideInset"
    android:verticalSpacing="@dimen/grid_view_margins" />
Maarten
  • 6,894
  • 7
  • 55
  • 90
  • If you're trying to only get padding on the lefthand and righthand side of the `GridView`, why not set the related `android:paddingLeft` and `android:paddingRight` attributes? `android:padding` will affect all four sides of the view. – MH. Apr 06 '13 at 00:46
  • 1
    I do want padding on top, I just want to be able to scroll across. – Maarten Apr 06 '13 at 07:19
  • Ah, I'm with you now. In that case, I suppose the easiest way to accomplish what you're after is to make the top padding part of the grid item. So basically your items will be square, plus some extra padding at the top that will then be scrolled across (and then remove the top padding from the `GridView` container). – MH. Apr 07 '13 at 05:30
  • possible duplicate of [GridView rows outer margin](http://stackoverflow.com/questions/17138943/gridview-rows-outer-margin) – Ram Patra Feb 24 '15 at 11:38

1 Answers1

51

android:clipToPadding="false" will solve your purpose

Shashank Tomar
  • 861
  • 10
  • 15