10

How can I recreate the following view with the help of a GridView.

enter image description here

The number of items in the list is dynamic.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Bytecode
  • 6,551
  • 16
  • 54
  • 101
  • 3
    a smaller image would have been nice :) – WarrenFaith Jun 27 '12 at 13:45
  • I don't think the GridView supports differnt # of columns, so AFAIK you'd have to "fake it" by splitting your images in half and setting one to each column for the rows that you want to appear as a single column. Out of curiosity why would you want to make this out of a GridView instead of a RelativeLayout or something that would make it easier to achieve the effect you want. – FoamyGuy Jun 27 '12 at 13:47

2 Answers2

2

I guess that this is not a single GridView but a combination of multiple Layouts. Just make a LinearLayout and decide according to the content, which layout you want to have in a row.

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
  • I'm looking for something similar, but with a large number of elements in the row: http://stackoverflow.com/questions/11981294/gridview-like-android-widget-with-variable-lengths/ The drawback of using a layout is that when I scroll down, the bitmaps that go off the screen cannot be garbage collected. I would like to use the `GridView`'s ability to do that. – mparaz Aug 17 '12 at 14:10
  • You can use a ListView so you get the rows itself recycled. – WarrenFaith Aug 17 '12 at 23:00
  • I can't use a `ListView` because my `View` needs to contain images with different heights. It looks like I will need to develop my own custom control. – mparaz Aug 18 '12 at 10:28
  • heights stretching over rows? Like table with colums/row span? Well than you need to do it on your own. Maybe make the resulting view available for others? – WarrenFaith Aug 18 '12 at 10:36
  • Yes, with a row span. I'll give it a try. – mparaz Aug 18 '12 at 10:40
  • No luck doing it with a ScrollView with ImageViews inside. When I remove the Bitmaps that go off the screen, and put them back when they go back, they don't come back. I asked part of it here: http://stackoverflow.com/questions/12123634/imageview-setimagebitmap-does-nothing-inside-complex-layout-inside-ontouch-inte – mparaz Aug 27 '12 at 03:34
0

To obtain the layout you see you can use something like this:

<LinearLayout android:orientation="vertical">
    <!-- First row -->
    <View />

    <!-- Second row -->
    <LinearLayout android:orientation="horizontal" />

    <!-- Third row -->
    <LinearLayout android:orientation="horizontal" />

    <!-- Fourth row -->
    <View />

</LinearLayout>

If you want also the paged effect you can use a ViewPager

http://android-developers.blogspot.it/2011/08/horizontal-view-swiping-with-viewpager.html

Stefano Ortisi
  • 5,288
  • 3
  • 33
  • 41