Scrolling issues with GridView in Android - android

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.

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.

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

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.

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:
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.
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.
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.

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!

Related

Add background image to RecyclerView that moves with scrolling

I am trying to add background images, partially covered, to a scrollable view that move along with it. What's the best way to do that?
Below is my attempt. I created an image item, and set the item just below the image to have a negative offset at the top by using ItemDecoration. However, as you can see, the item suddenly appears and disappears.
My second idea is just to lump the image and first item into one single item, but that seems less clean. Anybody has some good suggestions?
Okay, I solved the sudden appearance/disappearance problem by giving the RecyclerView a -150dp layout_marginBottom. Now the recycler view extends below the screen and the first item persists until it goes offscreen. I then set 150dp paddingBottom to compensate for content loss at the bottom.
Now everything works perfectly. But I consider this approach a little hacky, and would love to see more ideas

Recycler View Scroll to middle of screen

Hello I am not sure if this would be a duplicate as my wording is probably not the best to describe this on a search. I have a recycler view with a list of strings. Everything works great however, is there a way to make the list scroll a little higher than the bottom of the parent view, in this case keep scrolling up until it hits the middle of the screen? the Recycler view would height is match parent. Thank you in advance!!
Please note: I didnt add code since this is just a regular recycler view nothing special added, let me know if the code is needed as well thank you!
Edit:
this is for a vertical scroll list only. The following images are some list images I got offline but hopefully they can show better what I am trying to accomplish:
I want to be able to scroll the list up to the middle as in the following picture for example:

How to keep views in scrollview (that are inside a linear layout) that are not visible from being created?

I have linear layout inside a scrollview, and i would like to keep those views which are not visible(which are inside the linear layout) from being created until they are either visible or near to being visible. Like adjacent to one that is visible. I don't know if for example if turning off visibility will keep the View from being created(in terms of resources), or if gone could be used.
Update: The reason I am asking this question is because scrolling is taking a heck of a long time when there are say 30 view elements in the linear layout. These are not large view elements either, about what you would find for a record in a listview. I should add that the whole scrollview is inside a fragment.
Thanks
You have a LinearLayout(vertical) with 30 children. If you scroll to the bottom, which views would then be "created"?
If only the visible(or near visible) ones, then you can't measure how far down in the scroll they will be any more.
If at that point you're just saying you should create them when they first appear, and stay around afterward, that could work. However, once you scroll around some, you'll still have a bunch of views, and the same problem you have now.
Scrollviews exist and I happen to be using one.
True, but that doesn't necessarily means it's the best tool for the job. I tried something similar with my first Android project. I didn't know much about ListViews, and ended up rolling my own adapter that sounds eerily similar to what you're doing.
Long story short, the performance was bad. It did work, but once I(finally) switched to a ListView, the difference was nothing short of amazing. I'm just trying to keep others from going down that road. It was days of wasted time trying to get it "just right".

ContextMenu for blank space of an Android ListView

Is there a way I can get a context menu pop up when a user long presses on the blank space of a listview? I know that this can be done by setting wrap_content to the layout_height parameter of the listview. In fact I have been doing that successfully for a while. However, sometimes this wrap_content behaves very strangely and though there is enough space on the screen the listview restricts itself to a % of the screen and items scroll within that space. To avoid that problem I have moved to the path of setting the height as 0dp and weight as 1. However, that has disturbed the functionality I had in terms of long pressing the empty area of a list to add a new item to the list. Any help will be greatly appreciated.
Note: I have looked at multiple similar questions on SO throughout the day today but couldn't find any conclusive and elegant solution.
You can use ListView#addHeaderView() or ListView#addFooterView() to add extra view at the top or bottom of ListView, which you can make it looks like blank space.
Also I suggest you use match_parent to the layout_height attribute of ListView.

Is there a way to define a list height as the height of all its items? (Android)

I asked this question earlier, but I didn't really understand the only response I got. I'm having some problems writing a program that adds to a list dynamically at runtime. The program has some things above the list and the idea is that the user scrolls down to see the list that the program generates based on the user's input. However, when I use a list it is impossible for the user to see the lower parts of the list because the list takes up a set amount of space and if you try to scroll, the parent ScrollView takes over and assumes that you are trying to scroll the entire activity.
Is there a way to make the List height expand dynamically to wrap the children that are added so that the user can see all of the items in the list while using the Scrollview's scrolling ability? I have tried setting the height to wrap_content, but that did not work. Any help is appreciated. Thanks.
The Android engineers have stressed that ListViews should never be put in ScrollViews. This answer might be of some help to you.

Categories

Resources