Android ListView 被可绘制对象替换或显示不正确的背景

发布于 2024-12-08 17:24:26 字数 537 浏览 1 评论 0原文

我在单个 Activity 中的一组 ListView 中看到了一些非常奇怪的行为。

我有 5 个 ListView,它们构成了一个自定义控件,其作用类似于公文包上的锁组合。所有 5 个都有透明背景,并且使用relativelayout 将它们覆盖在背景之上。

每隔一段时间,所有 5 个 ListView 背景都会填充我在同一 Activity 上拥有的可绘制 png 图像。当此图像显示时,ListView 中没有应有的元素。我通常清理项目并将其推回到手机上,从而解决问题。然而,我试图弄清楚这个问题是否会发生,无论它是否开箱即用。

我不确定 ListView 是否完全被可绘制对象取代。我确实知道,当问题发生时,ListView 中永远不会有任何元素。

什么会导致图像资源显示为 ListView,而不是 ListView 及其内容?

更新: 我认为这可以通过清理/重建项目来解决,但是我现在发现这个问题发生在运行时。

替换主屏幕上的图像后,我发现错误加载到 ListView 中的图像实际上来自另一个 Activity。

I am seeing some very weird behavior with a set of ListViews that I have in a single Activity.

I have 5 ListViews that make up a custom control that acts like a lock combination on a briefcase. All 5 of these have transparent backgrounds and they are overlaid on top of their background using a RelativeLayout.

Every once and a while, all 5 of the ListView backgrounds will be filled with a drawable png image that I have on the same Activity. When this image shows up, there are no elements in the ListViews like their should be. I usually clean the project and push it back onto the phone which fixes the problem. However, I am trying to figure out if the issue will happen whether or not it worked out of the box.

I am not sure if the ListView is being entirely replaced by the drawable. I DO know that there are never any elements in the ListViews when the issue occurs.

What would cause the issue of an image resource showing up as the ListView, instead of the ListView and their contents?

Update:
I thought this could be resolved by cleaning/rebuilding the project, however I'm now finding out that this problem occurs during run-time.

After replace an image on the home screen, I found that the image being incorrectly loaded into the ListView is actually from another Activity.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

明天过后 2024-12-15 17:24:26

如果我为 ListViewandroid:divider 使用自己的透明 #00000000 颜色,我会看到这个问题。

修复方法是改用 @android:color/transparent,并且行为会自行纠正。

If I used my own transparent #00000000 color for the android:divider of the ListView, I would see this issue.

The fix was to use @android:color/transparent instead, and the behavior corrected itself.

淤浪 2024-12-15 17:24:26

如果图像是布局 XML 中父元素的背景,那么当列表为空时它将显示。

If the image is the background of a parent element in your layout XML, then it will show up when your lists are empty.

染年凉城似染瑾 2024-12-15 17:24:26

或者,当列表中没有元素时,您的 ListView 是否指定要显示的空图像?

Alternatively, does your ListView specify an empty image to be displayed when there are no elements in the list?

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