Reputation: 143
I am implementing a timeline UI, which is basically a ListView
. The tricky part is when the user scrolls the ListView
, it will display a text box(shows the time slot, say 9:00 am ) next to the scrollbar. It is on the left side, adjacent and will move with the scrollbar.
I am using the OnScrollListener
to detect the scroll event. But I don't know how to get the exact position of the scroll bar (top, mid point, bottom), so that I can put the text box at the right place. There are many posts about getting the position of the top item but seems not for the scrollbar itself.
Any thoughts?
BTW, sorry for not attaching a screenshot of the UI. Stackoverflow doesn't allow me to do that since I am a new user.
Upvotes: 2
Views: 2601
Reputation: 40503
getListView().getLastVisiblePosition()
listview.post(new Runnable() {
public void run() {
listview.getLastVisiblePosition();
}
});
View.getScrollY()
getScrollY: Return the scrolled top position of this view. This is the top edge of the displayed part of your view. You do not need to draw any pixels above it, since those are outside of the frame of your view on screen.
Returns The top edge of the displayed part of your view, in pixels.
Upvotes: 0
Reputation: 87064
But I don't know how to get the exact position of the scroll bar (top, mid point, bottom), so that I can put the text box at the right place
You probably want something like the Path
application. This tutorial it what you're looking for(probably, if you didn't see it yet).
Basically, the ListView
has some methods regarding the scrollbars position(also size) that are used but those methods are not available from outside as they are declared as protected
, so you need to extend the ListView
class. Those methods are ListView.computeVerticalScrollExtent()
, ListView.computeVerticalScrollOffset()
and ListView.computeVerticalScrollRange()
.
Using those methods you should be able to figure where the scrollbars are placed at a particular moment in your listener.
Upvotes: 0