Gallery setSelection 不会触发图像选择器
我有画廊小部件,当您滚动它时,当前选定的图像有边框 - 只是简单的选择器,就像这样
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:drawable="@drawable/thumbnail_frame" />
<item
android:drawable="@android:color/transparent" />
在画廊适配器的 getView 中,它的附件如下所示
image.setBackgroundDrawable(getResources().getDrawable(R.drawable.xxx));
问题是,当我使用 setSelection() 更改画廊选择时,所选项目没有边框。但是,当我只是用手指边框在所选项目上滚动它时,效果就可以了。我认为, setSelection() 不会触发 setSelected() 或类似的东西。
我想,解决方案是与 setSelection() 一起调用 setSelected() ,但是如何为当前选定的 ImageView 调用它?或者还有其他方法可以做到这一点吗?
I have gallery widget, when you scroll it, currently selected image has border - just simple selector, like this
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:drawable="@drawable/thumbnail_frame" />
<item
android:drawable="@android:color/transparent" />
and in gallery adapter's getView its attached like this
image.setBackgroundDrawable(getResources().getDrawable(R.drawable.xxx));
The problem is, when I change gallery selection with setSelection(), the selected item doesn't have a border. But when I just scroll it with finger border on selected item works OK. I think, setSelection() does not fire setSelected() or something like this.
I suppose, the solution would be to call setSelected() alongside setSelection(), but how do I call it for currently selected ImageView? Or is there some other way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 ViewPager 和 setCurrentItem。他们工作得更好。
Use a ViewPager and setCurrentItem. They work much better.