RecyclerView - 按下状态的项目混乱了

4

我创建了一个如下所示的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);

我长按一个图标并开始滚动,有时会导致已回收视图看起来像是被按下...我在我的RecyclerView项上使用简单的"android:background="?android:attr/selectableItemBackground""。如何解决这个问题或者什么可能是根本原因?
一些事实:
- 回收视图正常工作,文本和图片更新如预期。 - 仅仅背景没有重置,即使项目没有被触摸,看起来仍然是被按下的... - 我正在WindowManager中使用RecyclerView而不是在Activity中使用。

android:clickable="true" android:focusable="true" https://dev59.com/I2Af5IYBdhLWcg3wKwD4#25011355 - 林奕忠
1个回答

0

创建一个可绘制对象

<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>

将此可绘制对象设置为您使用的row_layout。它会起作用的。


我已经尝试过没有动画的可绘制对象,但这并没有解决问题。我认为选择器中的动画可能会引起问题。 - prom85
@prom85,这对我很有效。我使用它实现了RecyclerView的拖放功能和其他一些功能。 - Akshay Mukadam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接