滚动在 Google+ 中是如何工作的?安卓应用程序?

发布于 2024-11-26 16:25:46 字数 165 浏览 0 评论 0原文

我注意到,在使用它时,如果您在 Google+ Android 应用程序中的流中上下滚动,滚动条的大小会根据当前可见帖子的垂直大小而变化。例如,如果您滚动到长帖子,则该栏的大小会缩小,如果您滚动到短帖子,则该栏的大小会变长。这是如何实施的?

现在,我并不是特别需要这个功能,但这只是激起了我的好奇心。

I've noticed, while playing 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自在安然 2024-12-03 16:25:46

这是使用回收 ListView 的副作用。当新帖子滚动查看时,其余项目将被虚拟化 - 基本上 Android 会猜测列表的其余部分将占用多少空间,但它实际上不会渲染它们,因此无法确定。当您滚动到一个大帖子时,它会假设列表的其余部分也有大帖子,因此列表会更长。

您可以使用 getView 像这样:

@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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文