Android 中的图库自动滚动问题
我已经使用 Gallery View 一段时间了,并且已经启动并运行了基本的东西。但是,我在滚动时遇到问题。我尝试在谷歌中搜索,但没有找到解决此问题的简单方法。我正在使用基本适配器加载图像,完成后,我需要移动到特定位置(读取自动滚动)。我面临的问题是,假设我在图库中加载了 50 张图像,并且我想移动到第 30 个位置,我只需要调用 gallery.setSelection(30) 就可以了。仅当通过单击按钮调用时才有效。但是,我希望对活动负载本身执行相同的操作。一旦我将 BaseAdapter 与库绑定,我就无法知道绑定何时完成。我将不胜感激任何帮助。这就是我绑定适配器的方式。
gallery = (Gallery) findViewById(R.id.wpGallery);
ImageAdapter imgAdapter = new ImageAdapter(this);
gallery.setAdapter(imgAdapter);
我想移动到给定位置,并在移动到该位置后触发 onClickEvent。
I have been playing with Gallery View for sometime now and I have the basic stuff up and running. However, I have a problem with scrolling. I have tried to search in google and did not get a simple solution to this problem. I am loading images using a Base Adapter and once done, I need to move to a particular position(read auto scroll). The problem that I am facing is that, let's say I have 50 images loaded in the gallery and I want to move to the 30th position, I would just need to call gallery.setSelection(30) and I should be done. This works only when called from a button click. However, I want the same to be done on the activity load itself. Once I bind the the BaseAdapter with the gallery, I am not able to find out when exactly the binding is completed. I would appreciate any help on this. This is how I am binding the adapter.
gallery = (Gallery) findViewById(R.id.wpGallery);
ImageAdapter imgAdapter = new ImageAdapter(this);
gallery.setAdapter(imgAdapter);
I want to move to the given position and also trigger the onClickEvent once it has moved to that position.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否有效。但值得一试。
将此代码放在 onCreate 中,
在视图组在屏幕上布局后调用 OnGlobalLayoutListener。您应该可以在这里执行 setSelection 。
I'm not sure if this will work. But its worth a try.
Put this code in onCreate
OnGlobalLayoutListener is called after the viewgroup is laid out on the screen. You should be able to do setSelection here.