开发者

Gallery setSelection does not fires image selector

开发者 https://www.devze.com 2023-03-18 02:05 出处:网络
I have gallery widget, when you scroll it, currently selected image has border - just simple selector, like this

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开发者_Python百科 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?


Use a ViewPager and setCurrentItem. They work much better.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号