解决方法GridView.scrollTo()? [英] workarounds for GridView.scrollTo()?

查看:788
本文介绍了解决方法GridView.scrollTo()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如这里,Android的GridView.scrollTo()不工作。该解决方案中提到的方法, setSelectedPosition ,似乎并没有在的 GridView的

As mentioned here, Android's GridView.scrollTo() doesn't work. The method the solution mentioned, setSelectedPosition, doesn't seem to exist in GridView

smoothScrollToPosition 没有工作,但我真的不想动画。

smoothScrollToPosition does work, but I really don't want the animation.

有关背景下,我有一个的CursorAdapter -backed 的GridView ,我想以重置,即滚动到顶部,当我改变光标。

For context, I have a CursorAdapter-backed GridView, and I want the view to "reset", i.e. scroll to the top, when I change the cursor.

推荐答案

我一直在使用 setSelection(INT位置)对于这一点,它似乎工作得精细。要滚动到顶部,只需要用0的位置。

I've been using setSelection(int position) for this, and it seems to be working just fine. To scroll to the top, just use 0 for position.

从文档:

如果在触摸模式中,项目不会被选择,但它仍然会被适当地定位。

If in touch mode, the item will not be selected but it will still be positioned appropriately.

编辑: 后加code setSelection 作为一个Runnable:

Added code to post setSelection as a Runnable:

albumsView.post(new Runnable() {
    @Override
    public void run() {
        albumsView.setSelection(0);
    }
});

这篇关于解决方法GridView.scrollTo()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆