android scrollbar length with different item sizes - android

I have a listview with a comments. Comments has different length(from 1 line to 20, for example).
And while I'm scrolling this listview, standard scrollbar increases and decreases, depending of what the comment I'm scrolling in this moment.
Why is it happening?

Maybe this is what you need. Just set it false
setSmoothScrollbarEnabled

I found this online on why this happens. Not sure why Google decided make lists height-agnostic.
If the ListView contains items with variable heights, the ListView has no way of knowing the full height of all the items it contains so the height of the thumb is calculated based on the number of items in the view and the number of items currently visible. The number of items currently visible varies, so the thumb height varies too.
On iOS the equivalent component (UITableView) requests the height of all items from the UITableViewDataSource before the view is shown so the overall thumb size can be known and kept consistent.
Max Howell, Last.fm developer
Why does the scroll bar change its length during scrolling?

Related

Adjust a horizontal recyclerview so the last visible item is partially visible?

I am thinking of adjusting the width of each item a bit dynamically depending on screen size and number of items, but i am not able to find an easy solution to test it on different screen sizes. Is there an easier way?

Adding minimum height to a list

I am trying managing 4 lists under the same header as like it is posted in https://github.com/kmshack/Android-ParallaxHeaderViewPager. The problem I am facing is, my list has only fewer items on swiping pages, The header seems resizing. Is there a way to add a minimum height to the list to that it never falls short of height.

Android ListView Scrollable

Is there a way to determine if a list view needs to scroll to display all of its contents?
In other words, are the combined heights of all the children greater than the height of the list view itself.
I have not tried using it this way, but in principle if getLastVisiblePosition() equals getCount()-1, all items should be visible. It's possible that there is still a bit of scrolling needed, less than the height of a row, and I don't know if that matters in your case or not.
If it does, you could always iterate over the visible children and sum their heights.
I tried some ways a while ago and ended with simply calculating and comparing the height of the list view with the sum of the heights of all items and the sum of all separators.

How to create NxN non scrollable grid?

How can I create NxN grid which automatically scale its items to fit entire screen? I need something similar to GridView but without scrolling. I want to have all items visible and fit to screen dimensions.
Well you can get the size that the gridView can fit to, and then set each of the gridView's views size according to it.
This way, there will not have to be a scrolling at all.
So, for example, if you need an NxN grid and you have 100Nx100N pixels available, for each item give 100x100 pixels.
Of course, you might want to add some padding or separators between them, but that's the basic idea.
In order to get the gridView's size (so that you can set the size of each of its views), you can use this sample code I've made, which works on any type of view.

How can I find the measured height of views?

I need to calculate the measured height of my views without measuring all views, because these views contain images fetched from the internet. When I measure the views, they download images to memory and I an catch out of memory exception. I use custom ScrollViews, which work like ListViews, display some part of views and when scroll, add to bottom or top.
How can I calculate the height of all my views without throwing out of memory exceptions?
Or how can I make ListView calculate its height before rendering views?
You can use getLeft(), getTop(), getRight() and getBottom() these method's on view. for more information . see following link
http://developer.android.com/reference/android/view/View.html
You answered your own question:
display some part of views and when scroll, add to bottom or top.
ListView does NOT know the heights of items it has not yet seen. It lays out some or all of the items it knows, adds an extra bit of UI at top and bottom to visually indicate that there may be more items, and scrolls that. The total scrollable range for ListView can change as it adds more items.

Categories

Resources