Scrolling issues with GridView in Android
Asked Answered
L

5

25

I am having weird scrolling issues in my pretty simple GridView. Each item in the Grid is simply an ImageView and a TextView. The activity itself is simply an application selector. It looks like a rough version of the basic App Tray in Android.

The issue is that after spending some times scrolling through my view, it will inevitably allow me to continue scrolling past the top row of icons, to a blank screen, and the scroll bar will disappear, leaving me stuck.

It doesn't happen every time I go to the top of the view, only sometimes, and usually only after some excessive scrolling.

If I happen to notice the problem and catch it before the top row disappears off the bottom of the screen, I can usually scroll back through the view and spot some icons missing. There are empty spaces in the grid, and I can only assume that those icons have been moved to some bizarre position, which is allowing the view to scroll past the top.

This is my first Android app beyond a basic Hello World, so it's likely that I've just screwed up something in my layout files. I also realize that this is probably a pretty confusing description, so I'm hoping someone has experienced this and my search abilities simply were unable to find it.

I can post my layout files or other code if someone thinks that's useful.

Oh, and the program is built against 1.5, but is running on 2.2 (whatever state of 2.2 that was that snuck out last week) on my phone. I don't have enough apps to test this on an emulator, but could probably set something up if someone felt it necessary.

Thanks in advance for any help on the issue.

Lakshmi answered 1/6, 2010 at 2:40 Comment(2)
Please post the code for 1) your activity/list/item layout and 2) your adapter codeDandelion
can you solve,i meet this questionDollhouse
D
5

i have solved it: in the link GridView cannot show image you can try

Dollhouse answered 11/5, 2011 at 1:0 Comment(0)
O
10

I had same problem, but I post to GridView only ImageView's so pengwang's answer didn't help me. I found explanation for this bug https://code.google.com/p/android/issues/detail?id=16218

The problem is that GridView does not currently handle items with differing heights.

My solution is to use exactly specified layout_height same for all GridView's items.

Outrageous answered 19/4, 2013 at 11:56 Comment(1)
Thanks, this helped me solve a similar issue. First, i add some TextView's and Button's programmatically from getView(final int position, View convertView, ViewGroup parent) Then I use a getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {...} to get the max height per each row. Finally. I used the last column position to set every child height using viewGroup.getChildAt(position) to move among the View's in each row.Waits
D
5

i have solved it: in the link GridView cannot show image you can try

Dollhouse answered 11/5, 2011 at 1:0 Comment(0)
M
1

It seems that if you scroll off the bottom of the GridView and back again very fast a couple of times, you eventually will notice that the elements of the view get shifted one place to the "left" from where they originally were. When this happens, you then can scroll all the way off the top of the GridView. When you do reach the top of the list, item 0 is not displayed, having item 1 in its place and nothing but blackness above that row.

Clicking on any item in this situation resets the list and everything is back to normal.

This must be a bug. It's highly reproducible, and I don't think anything I'm doing is causing the mix up. At this point, adding to the list adapter has stopped.

Right now I'm working with Android 2.3.3.

Maura answered 27/4, 2011 at 20:32 Comment(1)
"At this point, adding to the list adapter has stopped."can you give me more detail.i meet this question https://mcmap.net/q/539837/-gridview-cannot-show-imageDollhouse
O
0

I just ran into this exact same issue myself -- I have a grid of images that have different heights. After reading the Android developer's doc on GridView, GridView.LayoutParams and GridLayout, I did two things that fix my issue:

  1. find the tallest image in each row, and store the height in a map of row -> rowHeight. Each image that I download has width and height info, so this is easy for me to do by overriding my adapter's addAll(items) method.

  2. in getView(), I create a GridView.LayoutParams(MATCH_PARENT, getRowHeight(position)), which sets each grid item to the max row height for its specific row.

  3. wrap my ImageView inside a LinearLayout. I have tried other layout but LinearLayout is the one that works. Set android:scaleType="fitCenter" and android:adjustViewBounds="true" for the image view.

After above 3 steps I finally got the grid to look right, they have different heights, and there's no scrolling issues.

Oscine answered 6/8, 2014 at 8:48 Comment(0)
S
0

I had a similar, but probably less common problem, where just scrolling a little bit would scroll the gridview to the end and I was not able to scroll up at all. This only occurred when the gridview was smaller, for example when the keyboard was visible. The problem was that I used:

    android:paddingBottom="400dp"
    android:clipToPadding="false"

Making padding bottom much smaller fixed my issue. I hope this helps at least someone!

Scream answered 1/1, 2020 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.