How does scrolling work in the Google+ Android app?
I've noticed, while p开发者_如何学Golaying around with it, that if you scroll up and down in the stream from the Google+ Android app, the scroll bar changes size depending on the vertical size(s) of the currently visible post(s). For example, if you scroll into a long posting, the bar shrinks in size, and if you scroll into a short post, it lengthens. How is this implemented?
Now, I don't particularly need this feature, but it's just something that has piqued my curiosity.
It's a side effect of using a recycling ListView
. As new posts are scrolled in to view, the rest of the items are virtualized - basically Android guesses as to how much space the rest of the list will take up, but it doesn't actually render them so it can't be sure. As you scroll on to a big post, it assumes the rest of the list has big posts in it and therefore the list is longer.
You can get the same functionality by using the convertView
parameter of getView
like so:
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = null;
if(convertView == null)
{
view = // set your view here
}
else
{
view = convertView
}
// set all your properties on the view here.
return view;
}
精彩评论