Android Gridview - Items align in direction of scroll

736 Views Asked by At

This is basically the same question as GridView - sometimes rows are top-aligned, sometimes they're bottom-aligned! but that doesn't seem to provide a sufficient answer, or at least one that works with my problem.

I have a gridview with items in it. In the item there is an image at the top followed by 3 textviews. Sometimes, depending on the value, one or two of the textviews will take up multiple lines.

When scrolling down this is fine, the image at the top is aligned with all other rows. But when you scroll the opposite direction, it's the very bottom textview that is aligned and the top of the images are out.

I will try and draw an example below.

Scrolling down

------    ------    ------

Image     Image     Image

------    ------    ------
TView1    TView1    TView1
------    ------    ------
TView2    TView2    TView2
------    TView2    ------
TView3    ------    TView3
------    TView3    ------
          ------

Scrolling Up

          ------
------              ------
          Image 
Image               Image
          ------
------    TView1    ------
TView1    ------    TView1
------    TView2    ------
TView2    TView2    TView2
------    ------    ------
TView3    TView3    TView3
------    ------    ------

I've read that I should be using layout_gravity="top" but that doesn't work. I thought it was possibly because layout_gravity isn't supposed to work in relativelayout, which is what my item is using, but when changing that to a linearlayout, it still didn't work.

Thanks

1

There are 1 best solutions below

7
On

Height of the every cell in the GridView must stay same, otherwise you will end up with such issues.