开发者

Handling selected/unselected states with ImageView as Tab indicators

I'm using ImageViews for my Tab indicators in a TabActivity. I have two copies of 开发者_Python百科the same jpeg file, one scaled to 75% of the original. What I want to be able to do is use the normal size for selected and the smaller for unselected.

StateListDrawable doesn't work with ImageView so I figure I have to handle this myself. All I can find that seems to relate to tab selection changing is TabHost.onTabChanged(String tabId) - I assume the tabId is the String I passed to new TabSpec(...).

Is this the only way to track tab changes? It would be useful to have an event handler (or handlers) to allow the previously selected tab to change view state and then the new tab to do the same. I can maintain a variable such as int currentSelection but it would be useful if it could be a bit more automated.


Solution: My ideal approach was to use StateListDrawables with my ImageViews but I was getting a ClassCastException when attempting to use ImageView.setImageDrawable() with xml files defining the state images.

The answer is to use setImageResource() instead, it works perfectly for what I need. Thanks to CommonsWare for pointing me in the right direction.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜