ListView onItemClick 区域在手机和手机上是不同的药片
我有一个 ListView,它已经被构造、样式化,并且有一个由两种设备通用的代码设置的适配器。
然而奇怪的是,在我的手机(2.3.4)上只有文本是可点击的。在平板电脑 (3.1) 上,整个 ListView 项目都是可单击的。在平板电脑上,文本也是右对齐的。
唯一的区别是,在平板电脑上,ListView 的 LayoutParams 宽度以编程方式设置为“240dp”。
到目前为止,我还没有向适配器(SimpleCursorAdapter)中的视图或ListView 本身添加任何侦听器。
以前有人遇到过这个吗?
I have a ListView which has been constructed, styled and had an adapter set from code which is common across both devices.
Curiously however, on my phone (2.3.4) only the text is clickable. On the Tablet (3.1) the entire ListView item is clickable. On the tablet the text is also right aligned.
The only difference is that on the Tablet the ListView has had it's LayoutParams width set programmatically to "240dp".
So far I haven't added any listeners to either the Views from the adapter (a SimpleCursorAdapater) or on the ListView itself.
Has anyone run into this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
准备好结束这一切了,
我最终在调查中偶然发现了解决方案:
我更改了管理
ListView
的 XML - 它被设置为"wrap_content"
(因此ListView
的宽度是列表中最大元素的宽度)。相反,我将其宽度设置为“match_parent”以在其容器上拉伸。显然,设置为“match_parent”的
ListView
的每个项目都将继承其父项的初始属性,而不是其当前属性(至少在宽度/高度方面)。如果你问我的话,我就打破了不直观的逻辑。Bit ready to end it all at this point,
I eventually stumbled upon the solution in my investigations:
I changed the XML governing the
ListView
- It was set to"wrap_content"
(so the width of theListView
was the width of the largest element of the list). I instead set it's width to"match_parent"
to stretch across it's container.Apparently each item of a
ListView
set to"match_parent
" will inherit the initial attributes of their parents, not their current attributes (at least not in terms of width/height). Broken unintuitive logic if you ask me.