GridView with dynamic number of columns in each row
Asked Answered
C

2

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.

Constitutional answered 27/6, 2012 at 13:41 Comment(2)
a smaller image would have been nice :)Protanopia
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.Expressway
P
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.

Protanopia answered 27/6, 2012 at 13:46 Comment(6)
I'm looking for something similar, but with a large number of elements in the row: #11981794 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.Mysterious
You can use a ListView so you get the rows itself recycled.Protanopia
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.Mysterious
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?Protanopia
Yes, with a row span. I'll give it a try.Mysterious
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: #12124134Mysterious
P
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

Pharmacopoeia answered 27/6, 2012 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.