看起来像将 RecyclerView 的项目布局设置为 clickable="true",完全消耗一些触摸事件,特别是MotionEvent.ACTION_DOWN
(之后的 ACTION_MOVE 和 ACTION_UP 正在工作):
项目.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/demo_item_container"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"> <-- this what breaks touch event ACTION_DOWN
....
</LinearLayout>
在 onCreate() 中有非常基本的 RecyclerView 设置:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
... //Standard recyclerView init stuff
//Please note that this is NOT recyclerView.addOnItemTouchListener()
recyclerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Log.d("", "TOUCH --- " + motionEvent.getActionMasked());
//Will never get here ACTION_DOWN when item set to android:clickable="true"
return false;
}
});
RecyclerView 中的这种预期行为或错误是否导致它仍然是预览版?
PS。我希望根据文档可以点击它以对按下状态做出反应并对点击产生连锁反应。当设置为 false 时,ACTION_DOWN 工作正常,但未触发按下状态,并且 selectableBackground 没有任何效果。