滑动时获取 GalleryView 上图像的位置?

发布于 2024-10-09 16:47:03 字数 31 浏览 0 评论 0原文

如何在滑动时获取当前图像在图库视图中显示的位置?

How can I get the position of current image displaying in Gallery view while it is swiping?

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

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

发布评论

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

评论(2

再可℃爱ぅ一点好了 2024-10-16 16:47:03

因此,由于适配器视图的工作方式,我认为这是不可能的。基本上,大多数(如果不是全部)对适配器视图适配器的调用都必须在 UI 线程上才能正常工作。而且动画肯定是在UI线程上的。因此,由于它们不能在同一线程上同时发生,因此在滑动动画结束之前您实际上无法(准确地)读取位置。

如果您在任何其他线程上询问适配器 getSelectedItemPosition(),它可能会为您提供当前位置,但也可能会过时一段时间,因为我猜测 UI 线程将在不检查独占锁的情况下更新该值。

So I don't think that is possible because of the way adapter views work. Basically most if not all calls to the adapter view's adapter have to be on the UI thread to work properly. And the animation is definitely on the UI thread. So since they both can't be happening at the same time on the same thread, you can't actually (accurately) read the position until the swiping animation is over.

If you ask the adapter getSelectedItemPosition() on any other thread it might give you the current position but might also be stale for some time since I am guessing the UI thread is going to update the value without checking for an exclusive lock.

樱花落人离去 2024-10-16 16:47:03

我们可以在图库视图中滑动图像时获取位置,您可以覆盖图库视图的setOnItemSelectedListener

我们有两个来自该监听器的方法,例如

avatar_gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, 
                                View view, 
                                int position, 
                                long id){                  
        Log.v("Selected", ""+position);
    }
    @Override
    public void onNothingSelected(AdapterView<?> parent){
    }
}

We can get the position when we are swiping the image in gallery view,you overwrite Gallery View's setOnItemSelectedListener.

We have two methods from that listener like

avatar_gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, 
                                View view, 
                                int position, 
                                long id){                  
        Log.v("Selected", ""+position);
    }
    @Override
    public void onNothingSelected(AdapterView<?> parent){
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文