0

I'm trying to use the GridView to create an image gallery index that will look similar to the Ice Cream Sandwhich gallery app:

http://www.techdron.com/wp-content/uploads/2011/10/sw_albums.jpg

(Sorry I can't use the img tag yet)

I'm looked at all of the common tutorials (e.g. http://developer.android.com/resources/tutorials/views/hello-gridview.html) and none of them really give me what I'm looking for.

Right now I have the following:

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="100dp"
android:numColumns="auto_fit"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:stretchMode="none"
android:gravity="center"
android:layout_weight="1"
android:background="#000000"/>

And I am creating my views in the adapter like so:

imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(148,148));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

It's close but the feeling really isn't the same, and I'm not sure that it will scale well on all devices. Does anyone know of a way to use the GridView like this? Or should I be looking at using another widget, e.g. the GridLayout.

Thanks.

TZHX
  • 5,291
  • 15
  • 47
  • 56
selsine
  • 2,813
  • 2
  • 21
  • 22

1 Answers1

0

As you have mentioned that you have taken ImageAdapter from the GridView example.

Here i would suggest you to create a custom adapter class, follows the below steps:

  1. Define a row XML layout with the widgets you want for one item in GridView. Say for example, ImageView and one TextView at bottom corner of ImageView (As given in Gallery view in ICS)

  2. Now, define a custom adapter class, say for example, MyAdapter and extends BaseAdapter class.

  3. After extending BaseAdapter class you have override some methods, inside the getView() method, you have to inflate the row XML layout (step-1) and do display kind of operations like Setting text in TextView, etc.

  4. Now set this adapter to your GridView. Done!!

For finding example, search for "Android GridView example" and scroll to my blog link, you will get it. Here i can't paste it.

Community
  • 1
  • 1
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • That's what I have going on, it's close, but it still doesn't look as nice as the ICS gallery. It feels a bit more wooden. – selsine Apr 13 '12 at 14:30