ListView onItemClick 区域在手机和手机上是不同的药片

发布于 2024-12-06 15:40:29 字数 297 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余厌 2024-12-13 15:40:29

准备好结束这一切了,

我最终在调查中偶然发现了解决方案:

我更改了管理 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 the ListView 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文