gpt4 book ai didi

android - RecyclerView - 项目的按下状态变得困惑

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:32 25 4
gpt4 key购买 nike

我创建了一个 RecyclerView,如下所示:

recyclerView.setLayoutManager(new GridLayoutManager(getContext(), cols, LinearLayoutManager.VERTICAL, stickToBottom);
recyclerView.setAdapter(adapter);

// completely disable animations... just to test if this solves the problem
recyclerView.setItemAnimator(null);

我长按一个图标并开始滚动,有时,这会导致循环 View 看起来很压抑...我使用的是一个简单的 "android:background="?android:attr/selectableItemBackground"在我的 recyclerview 项目上。

我该如何解决问题或问题的根本原因是什么?

一些事实

  • 回收 View 效果完美,文本和图像按应有的方式更新
  • 只有背景没有重置并且看起来很压抑,即使项目没有被触摸...
  • 我在 WindowManager 中使用 RecyclerView 而不是在 Activity 中..

最佳答案

创建可绘制对象

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="false" android:drawable="@color/white" />
<item android:state_pressed="true" android:drawable="@color/highlight_color" />

</selector>

将此 drawable 设置为您使用的 row_layout。它会起作用。

关于android - RecyclerView - 项目的按下状态变得困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32559649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com