0

How to fill a GridView with vertical images (rectangles), keep the gridview autofit so that it choose the good number of columns by itself.

here is my grid view and the cell :

<GridView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:gravity="center"
    android:horizontalSpacing="@dimen/margin_medium"
    android:numColumns="auto_fit"
    android:overScrollMode="never"
    android:paddingLeft="@dimen/margin_large" <!-- 16dp -->
    android:paddingRight="@dimen/margin_large"
    android:paddingTop="@dimen/margin_large"
    android:scrollbars="none"
    android:stretchMode="columnWidth"
    android:verticalSpacing="@dimen/margin_medium" > <!-- 8dp -->
</GridView>

The Cell

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="@dimen/grid_cell_width" <!-- 359dp -->
    android:layout_height="@dimen/grid_cell_height" <!-- 600dp -->
    android:background="@drawable/selector_list_simple"
    android:padding="@dimen/margin_small" >  <!-- 4dp -->

    <ImageView
        android:id="@+id/cell_allzic_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:scaleType="centerInside" >
    </ImageView>

    <ProgressBar
        android:id="@+id/cell_allzic_loading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:indeterminate="true"
        android:indeterminateDrawable="@drawable/progress_bar_custom"
        android:visibility="gone" />

</RelativeLayout>
An-droid
  • 6,433
  • 9
  • 48
  • 93
  • Try this : https://github.com/maurycyw. Check out the StaggeredGridView lib. It works fine when images in the Grid are of uneven sizes. Check out the demo there as well. – Dhaval May 07 '14 at 12:16
  • If you feel like you want to implement it, here's the link how you do it swiftly. http://stackoverflow.com/questions/22701363/use-etsys-staggeredgridview-in-eclipse – Dhaval May 07 '14 at 12:17
  • @Dhaval : StaggeredGridView seems like a good lib but it is too much for what i want to do. The only thing i want to achieve is to have all the cells with the same size and align, with no definite number of columns (autofit). – An-droid May 07 '14 at 12:32

0 Answers0