Android ListView 被可绘制对象替换或显示不正确的背景
我在单个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我为
ListView
的android:divider
使用自己的透明#00000000
颜色,我会看到这个问题。修复方法是改用
@android:color/transparent
,并且行为会自行纠正。If I used my own transparent
#00000000
color for theandroid:divider
of theListView
, I would see this issue.The fix was to use
@android:color/transparent
instead, and the behavior corrected itself.如果图像是布局 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.
或者,当列表中没有元素时,您的 ListView 是否指定要显示的空图像?
Alternatively, does your ListView specify an empty image to be displayed when there are no elements in the list?