如何突出显示图库中当前选定的项目?
我是带着问题来的。我需要突出显示图库中的所选项目。我尝试通过此方法更改所选视图的外观:
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
该视图的第二个参数是当前所选视图,在这种情况下,我尝试增加文本的大小。但是,即使我在所选项目或整个图库中调用 invalidate,这也不起作用。
这是我用来更改文本视图文本大小的代码
TextView textview = (TextView)view;
textview.setTextSize(50, TypedValue.COMPLEX_UNIT_SP);
textview.invalidate();
你知道该怎么做吗?谢谢
I've come with a problem. I need to highlight the selected item within a Gallery. I've tried changing the appearance of the selected view through this method:
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
The second parameter of that view is the current selected view, and I'm trying in this case, increase the size of the text. However this doesn't work, not even if I call invalidate in the selected item or in the entire Gallery.
This is the code I use to change the textview text size
TextView textview = (TextView)view;
textview.setTextSize(50, TypedValue.COMPLEX_UNIT_SP);
textview.invalidate();
Do you know how to do this? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的实现有效,但一旦取消选择该项目,它不会将文本大小恢复为正常 - 文本保持较大尺寸。
这应该可以解决这个问题:
您可以设置文本大小而不是颜色,或者对其样式进行任何您想要的操作。
Your implementation works, but it does not return the text size to normal once the item becomes unselected - the text stays larger size.
This should fix it:
You can set text size instead of color, or do whatever you want to the style of it.
尝试 StateListDrawable - 看起来很适合您的情况。
更新:您已反转 setTextSize 中的参数。应该是:
Try StateListDrawable - looks apt for your situation.
UPDATE: You have reversed the parameters in setTextSize. It should be: