Android ListView 与 Style 到元素的问题;滚动样式自动改变后

发布于 2025-01-01 23:03:17 字数 451 浏览 1 评论 0原文

我的应用程序中有一个自定义 ListView,它内部有一些 TextView,在运行时向其提供样式。当我向下滚动 ListView 并再次向上滚动时,之前给 TextView 提供的样式会更改为某种不同的样式。 有什么办法可以防止这种情况发生吗?

我认为,将所有代码放在这里会使页面看起来很丑。因此,请按照以下链接获取代码 -

MyAdapter.java

CustomListItem.java

I have a Custom ListView in my application and it has some TextViews inside it to which the styles are provided at run time. When I scroll down the ListView and again scroll up, the styles given previously to the TextView changes to some different style.
Is there any way to prevent this?

I think, putting all the code here will make the page look ugly. So kindly follow these links for code-

MyAdapter.java

CustomListItem.java

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

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

发布评论

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

评论(2

心清如水 2025-01-08 23:03:17

您使用自定义适配器吗?也许是不正确地重用convertView导致的一些问题,你能发布代码吗?

或者也许只是改变背景颜色?在这种情况下很简单:

android:cacheColorHint="#00000000"将完成这项工作。

ListView 的 XML 中的

Do you use custom Adapter? Maybe it is some issue with incorectly reusing convertView, can you post the code?

Or maybe it is just changing background color? In that case simple:

android:cacheColorHint="#00000000"

in ListView's XML will do the work.

空心空情空意 2025-01-08 23:03:17

我找到了解决它的方法。只需在“转换视图”中设置 TextView 一些默认样式,就像

textView.setTextAppearance(context , android.R.style.TextAppearance_Small);

在 ViewHolder 构造函数中以及在您用来将元素设置为默认状态的方法中一样。

I found a way to fix it. Just set the TextView with some default style in the "Convert View" like

textView.setTextAppearance(context , android.R.style.TextAppearance_Small);

in the ViewHolder constructor and in your method you use to set the elements to default state.

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