如果 Recycler View Item Click 位于 Swipe Refresh Layout 下则不起作用 - Android
Recycler View Item Click not working if its put under Swipe Refresh Layout - Android
如果我将回收视图放在滑动刷新布局中,回收视图项目点击不起作用。添加下面的布局。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_no_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="90dp"
android:layout_marginEnd="90dp"
android:gravity="center_horizontal"
android:lineSpacingExtra="6sp"
android:text="@string/no_orders_found"
android:textColor="#616161"
android:textSize="16sp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="@+id/progressView"
layout="@layout/layout_progress"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
android:clickable="false">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcv_inventory"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:padding="@dimen/padding_15dp"
android:focusable="true" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
当我删除滑动刷新布局时,点击有效。如何在不删除滑动刷新布局的情况下使回收站视图可点击?
更多信息:此布局是片段的一部分,片段用作视图寻呼机 2 的页面。我在 Recycler View 适配器中有两种视图类型
尝试将ConstraintLayout
替换为LinearLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_no_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="90dp"
android:layout_marginEnd="90dp"
android:gravity="center_horizontal"
android:lineSpacingExtra="6sp"
android:text="@string/no_orders_found"
android:textColor="#616161"
android:textSize="16sp"
android:visibility="gone"
/>
<include
android:id="@+id/progressView"
layout="@layout/layout_progress"
android:visibility="gone"
/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcv_inventory"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/padding_15dp"
/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
SwipeRefreshLayout
不应该是 RecyclerView
项目接收点击事件的拦截器,你也可以 post 你的 itemClickListener
实现吗?
此外,请考虑使用 FrameLayout
满足您的上述布局要求。
Use latest stable version of Constraint Layout. I have same problem because I am using old version.
dependencies {
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
}
如果我将回收视图放在滑动刷新布局中,回收视图项目点击不起作用。添加下面的布局。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_no_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="90dp"
android:layout_marginEnd="90dp"
android:gravity="center_horizontal"
android:lineSpacingExtra="6sp"
android:text="@string/no_orders_found"
android:textColor="#616161"
android:textSize="16sp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="@+id/progressView"
layout="@layout/layout_progress"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
android:clickable="false">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcv_inventory"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:padding="@dimen/padding_15dp"
android:focusable="true" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
当我删除滑动刷新布局时,点击有效。如何在不删除滑动刷新布局的情况下使回收站视图可点击?
更多信息:此布局是片段的一部分,片段用作视图寻呼机 2 的页面。我在 Recycler View 适配器中有两种视图类型
尝试将ConstraintLayout
替换为LinearLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_no_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="90dp"
android:layout_marginEnd="90dp"
android:gravity="center_horizontal"
android:lineSpacingExtra="6sp"
android:text="@string/no_orders_found"
android:textColor="#616161"
android:textSize="16sp"
android:visibility="gone"
/>
<include
android:id="@+id/progressView"
layout="@layout/layout_progress"
android:visibility="gone"
/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcv_inventory"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/padding_15dp"
/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
SwipeRefreshLayout
不应该是 RecyclerView
项目接收点击事件的拦截器,你也可以 post 你的 itemClickListener
实现吗?
此外,请考虑使用 FrameLayout
满足您的上述布局要求。
Use latest stable version of Constraint Layout. I have same problem because I am using old version.
dependencies {
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
}