I have a listview and its rows have different heights.
When I scroll up, rows appear to move up or down erratically.
(I don't find the behavior when I scroll down)
I suspect its due to the fact
listView picks one of used rows
the row is placed on top of visible rows.
listView changes the row's height(here erratic movement)
but it's a guess.
I tried googling since this should be a common problem but couldn't find any.
In this case, setting the right item height did the trick :
How to set different heights for each row in a ListView?
Edit: oh, and make sure you recycle the items correctly :
ListView reusing views when ... I don't want it to
Related
Let's say I have 100 rows of data to show in a ListView. So far no problem. I have a custom adapter for each row, that has a TextView for a date, a TextView for a sequence number and NOW 60 more TextViews, mostly having a two digit number.
How can I get a horizontal scroll to show all these 60 numbers, BUT, the vertical scroll for the Listview should still work, to scroll down from 1 to 100 row, and also, all rows shown on the screen shall scroll horizontal at the same time, not that only one row will scroll horizontal.
Had tried TwoWayView, but only allows to define one direction of scroll.
You need to have a horizontal scrolling list as each ListItem. Although, there are several horizontal scrolling view options, I would recommend using a Recyclerview with a LinearLayoutManager and orientation set to HORIZONTAL.
The general idea is you need a horizontal list as a list item.
I have a long list with a big header and footer and I need to scroll the list all the way down and show the whole footer.
Also, items can have very different height so the overall height cannot be simply calculated height * no items.
All the existing questions I've seen do not take in account the footer might be big and not entirely shown when scrolling to last position.
So far I've tried:
1) the simplest solution:
lv.setSelection(lv.getCount() - 1);
However this will not show the whole footer, only part of it and I need to have it all visible.
2) using:
requestFocus();
on the footer, the main layout in it, and any elements in the footer: this changes the focus but doesn't force the listview to scroll down.
3) using:
lv.scrollTo(x, y);
problem with this is that I couldn't get the real height of the listview in a reliable way as items are not fixed size.
Beside, after scrolling often part of the list is not shown leaving a wide white area.
4) header and footer are contained in two adapters but I couldn't figure out how to reach them to be shown on the screen
5) I have also tried a mixed approach:
lv.setSelection(lv.getCount() - 1);
lv.scrollListBy(mFooter.getHeight());
But the scrollListBy() doesn't seem to have any effects after a setSelection - not sure why.
Does anyone have any suggestions?
Thanks in advance
Using a GridView, is it possible to allow the item directly above and below all the visible items to remain in memory? (I have one column in my grid view)
I would like my adapter to prevent recycling for those items as long as they are direct neighbours to items that are currently visible.
My problem was that my GridView had some padding on both left and right side. This made the neighbouring items invisible/recycled "too fast".
Removing the padding resolved my issue.
I have a listview with rows as big as the device screen and I want to show row per row while sliding, I don't want to show parts of rows when doing so, is there any way of doing it.
ListViews are not made for this kind of use case. ViewPagers are, but they scroll horizontally. It's possible to make it scroll vertically (see Android: Vertical ViewPager), which should be what you're looking for.
The problem with adjusting the size of each ListView item to fill the screen is that match_parent simply doesn't work. You would need to calculate the exact size you need (screen height minus action bar and other views that are not part of the ListView). It's probably possible, but not worth the trouble.
I have an app which loads a boatload of images and displays them in a TableLayout which is inside a ScrollView. At run time I get the width of the layout parent and use that to determine how many images can go in each TableRow (all of the images are of a set size).
I'm concerned about memory issues when loading more and more images. I know ListView recycles its views but I don't know how to dynamically change number of views in each item. I am only aware of inflating XML which isn't going to change the number of views per item at run time.
So my question is what is easier - figuring out how to recycle views in my table by myself, or making a list's items change based on screen size? Just a link to a tutorial on how to do whichever is easier is good enough an answer for me.
I suggest you to use ListView with the ViewHolder approach (you can see it here: How to load the Listview "smoothly" in android).
The ListView, when scrolled, removes the views that are no more visible and gets the views that are about to become visible. This way, it's better than using a ScrollView and a TableLayout.