滚动时列表颜色变黑

发布于 2024-12-21 15:28:20 字数 83 浏览 0 评论 0原文

我有一个列表活动,当我单击一个选项卡时填充,问题是列表颜色在滚动时变黑,即使我没有设置任何属性来发生这样的情况..有什么建议可以避免这个问题吗? 谢谢,

I have one list activity which populates when I click on one tab, the problem is list colour turns black while scrolling it, even though i have not set any attributes to happen like that.. Any suggestions to avoid this problem?
Thanks,

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

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

发布评论

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

评论(4

森罗 2024-12-28 15:28:20

将其添加到 xml 文件中的 listView 中:

android:cacheColorHint="#00000000"

或在 Java 代码中:

getListView().setCacheColorHint(0);

Add this to listView in the xml file:

android:cacheColorHint="#00000000"

or in Java code:

getListView().setCacheColorHint(0);
动次打次papapa 2024-12-28 15:28:20

我建议您阅读这篇文章:ListView 背景:优化 ,这是定制LitsView外观之前必读的文章。

摘自上述文档:

如前所述,ListView 默认情况下具有透明/半透明背景,Android UI 工具包中的所有默认小部件也是如此。这意味着当 ListView 重绘其子级时,它必须将子级与窗口背景混合。再次,这需要从内存中进行昂贵的读回,这在滚动或快速滑动期间尤其痛苦,因为每秒绘制数十次。

为了提高滚动操作期间的绘图性能,Android 框架重用了缓存颜色提示。设置此提示后,框架会将列表的每个子项复制到填充有提示值的位图中(假设未关闭称为滚动缓存的另一种优化)。然后,ListView 直接在屏幕上位图传输这些位图,并且由于已知这些位图是不透明的,因此不需要混合。此外,由于默认缓存颜色提示为#191919,因此在滚动期间每个项目后面都会出现深色背景。

要解决此问题,您只需禁用缓存颜色提示优化(如果您使用非纯色背景),或者将提示设置为适当的纯色值。您可以通过代码(请参阅 setCacheColorHint(int))或最好通过 XML(使用 android:cacheColorHint 属性)来执行此操作。要禁用优化,只需使用透明颜色#00000000。以下屏幕截图显示了在 XML 布局文件中设置了 android:cacheColorHint="#00000000" 的列表

I would suggest you to go through this article: ListView Backgrounds: An Optimization, this is must read article before customizing look of LitsView.

Taken from above document:

As mentioned before, ListView has a transparent/translucent background by default, and so all default widgets in the Android UI toolkit. This implies that when ListView redraws its children, it has to blend the children with the window's background. Once again, this requires costly readbacks from memory that are particularly painful during a scroll or a fling when drawing happens dozen of times per second.

To improve drawing performance during scrolling operations, the Android framework reuses the cache color hint. When this hint is set, the framework copies each child of the list in a Bitmap filled with the hint value (assuming that another optimization, called scrolling cache, is not turned off). ListView then blits these bitmaps directly on screen and because these bitmaps are known to be opaque, no blending is required. Also, since the default cache color hint is #191919, you get a dark background behind each item during a scroll.

To fix this issue, all you have to do is either disable the cache color hint optimization, if you use a non-solid color background, or set the hint to the appropriate solid color value. You can do this from code (see setCacheColorHint(int)) or preferably from XML, by using the android:cacheColorHint attribute. To disable the optimization, simply use the transparent color #00000000. The following screenshot shows a list with android:cacheColorHint="#00000000" set in the XML layout file

も星光 2024-12-28 15:28:20

您是否可能在您的活动或应用程序上设置了一个使用“

<item name="android:windowBackground">@null</item>

这是一个技巧”的主题,当您有一个填充父级的视图(通常是 SurfaceView)时,它可以大大加快 2D 绘图的速度。我发现这会导致 listViews 和scrollViews 的背景渲染出现奇怪的情况。

如果您使用空窗口背景黑客,您可以尝试为列表视图设置背景颜色,我敢打赌滚动问题将会减轻。

Did you perhaps set a theme on your activity or app that uses the

<item name="android:windowBackground">@null</item>

This is a trick that speeds up 2D drawing quite a bit when you have a view (usually surfaceView) that fills parent. I have see this cause odd background rendering of listViews and scrollViews.

If youre using the null windowbackground hack, you might try setting a background color for your list view and I bet the scrolling issues will abate.

忆悲凉 2024-12-28 15:28:20

我知道回答这个问题已经很晚了,但对于面临这个问题的其他人来说:

上述技术可能有效,但实际应该做的是添加

android:scrollingCache="false"

列表布局。像这样

     <ListView 
   android:layout_width="30dp"
   android:layout_height="30dp"
   android:id="@+id/myList"
   android:scrollingCache="false"
    />

你可以从这里得到原因 scrollingCache?

谢谢

I know its late to answer this question but for others who are facing this problem :

Above techniques may work but the actual thing one should do is adding

android:scrollingCache="false"

in list layout. Like this

     <ListView 
   android:layout_width="30dp"
   android:layout_height="30dp"
   android:id="@+id/myList"
   android:scrollingCache="false"
    />

you can get the reason of this from here scrollingCache?

Thanks

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