使包含 Recyclerview 的 ConstraitLayout 可点击
我有一个 RecyclerView 放置在 ConstraintLayout 中。我想要实现的是使 ConstraintLayout 可点击和可聚焦,而不是 RecyclerView 或其项目。目前我只能关注 RecyclerView-items 周围的区域。非常感谢任何帮助!
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/recyclerview_container"
android:layout_width="match_parent"
android:clickable="true"
android:focusable="true"
android:layout_height="wrap_content"
android:background="@drawable/select_background_top"
app:layout_constraintTop_toBottomOf="@id/safety_title">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/device_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/select_background_top"
android:paddingVertical="@dimen/half_content_padding"
app:layout_constraintEnd_toStartOf="@+id/recycler_view_arrow"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:itemCount="3"/>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/recycler_view_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/half_content_margin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_keyboard_arrow_right_24dp"
app:tint="@color/secondaryIconColor" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have a RecyclerView placed within a ConstraintLayout. What I am trying to achieve is making the ConstraintLayout clickable and focusable, not the RecyclerView or it's items. Currently I am only able to focus the area surrounding the RecyclerView-items. Any help highly appreciated!
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/recyclerview_container"
android:layout_width="match_parent"
android:clickable="true"
android:focusable="true"
android:layout_height="wrap_content"
android:background="@drawable/select_background_top"
app:layout_constraintTop_toBottomOf="@id/safety_title">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/device_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/select_background_top"
android:paddingVertical="@dimen/half_content_padding"
app:layout_constraintEnd_toStartOf="@+id/recycler_view_arrow"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:itemCount="3"/>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/recycler_view_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/half_content_margin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_keyboard_arrow_right_24dp"
app:tint="@color/secondaryIconColor" />
</androidx.constraintlayout.widget.ConstraintLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论