英文:
Ripple effect is not visible on the complete row
问题
我有一个RecyclerView,其中一行有一个复选标记和一个位于右侧的拖放(重新排列)图标,就像官方材料设计视频中的一样,我希望涟漪效果覆盖整个行。但是当我拉伸ImageView时,复选框不再可点击。这是否可能?
<FrameLayout
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="64dp"
    android:orientation="horizontal"
    android:background="@android:color/white"
    android:paddingLeft="@dimen/small_margin"
    android:paddingRight="@dimen/small_margin">
    <CheckBox
        android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start|center_vertical"
        android:checked="@{safeUnbox(viewModel.isEnabled), default=false}"
        android:padding="@dimen/small_margin"
        android:text="@={viewModel.abbreviation}"
        android:textAppearance="@style/TextAppearance.Compat.Notification.Title"
        tools:text="Bijbelvertaling" />
    <Space
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />
    <ImageView
        android:id="@+id/dragger"
        android:layout_width="40dp"
        android:background="?android:attr/selectableItemBackground"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical|end"
        android:scaleType="center"
        android:src="@drawable/ic_drag_handle_24px"
        android:contentDescription="拖放图标" />
</FrameLayout>
英文:
I have a RecyclerView with a row that has a checkmark and a drag & drop (rearrange) icon to the right. Just like in the official material design video, I want the ripple effect to be over the whole row. But when I span the ImageView, the CheckBox is not clickable anymore. Is this even possible?
   <FrameLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:orientation="horizontal"
        android:background="@android:color/white"
        android:paddingLeft="@dimen/small_margin"
        android:paddingRight="@dimen/small_margin">
        <CheckBox
            android:id="@+id/checkbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start|center_vertical"
            android:checked="@{safeUnbox(viewModel.isEnabled), default=false}"
            android:padding="@dimen/small_margin"
            android:text="@={viewModel.abbreviation}"
            android:textAppearance="@style/TextAppearance.Compat.Notification.Title"
            tools:text="Bijbelvertaling" />
        <Space
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1" />
        <ImageView
            android:id="@+id/dragger"
            android:layout_width="40dp"
            android:background="?android:attr/selectableItemBackground"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical|end"
            android:scaleType="center"
            android:src="@drawable/ic_drag_handle_24px"
            android:contentDescription="Drag and drop icon" />
    </FrameLayout>
答案1
得分: 2
请使用以下代码替代FrameLayout,并将涟漪效果android:foreground="?android:attr/selectableItemBackground"应用于根布局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layout"
    android:clickable="true"
    android:layout_width="match_parent"
    android:layout_height="64dp"
    android:orientation="horizontal"
    android:foreground="?android:attr/selectableItemBackground"
    android:background="@android:color/white"
    android:paddingLeft="@dimen/small_margin"
    android:paddingRight="@dimen/small_margin">
    <CheckBox
        android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:checked="@{safeUnbox(viewModel.isEnabled), default=false}"
        android:padding="@dimen/small_margin"
        android:text="@={viewModel.abbreviation}"
        android:textAppearance="@style/TextAppearance.Compat.Notification.Title"
        tools:text="Bijbelvertaling" />
    <ImageView
        android:id="@+id/dragger"
        android:layout_width="40dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:scaleType="center"
        android:src="@drawable/ic_drag_handle_24px"
        android:contentDescription="Drag and drop icon" />
</RelativeLayout>
英文:
Instead of FrameLayout use RelativeLayout like below and apply ripple effect android:foreground="?android:attr/selectableItemBackground" to root layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layout"
    android:clickable="true"
    android:layout_width="match_parent"
    android:layout_height="64dp"
    android:orientation="horizontal"
    android:foreground="?android:attr/selectableItemBackground"
    android:background="@android:color/white"
    android:paddingLeft="@dimen/small_margin"
    android:paddingRight="@dimen/small_margin">
    <CheckBox
        android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:checked="@{safeUnbox(viewModel.isEnabled), default=false}"
        android:padding="@dimen/small_margin"
        android:text="@={viewModel.abbreviation}"
        android:textAppearance="@style/TextAppearance.Compat.Notification.Title"
        tools:text="Bijbelvertaling" />
    <ImageView
        android:id="@+id/dragger"
        android:layout_width="40dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:scaleType="center"
        android:src="@drawable/ic_drag_handle_24px"
        android:contentDescription="Drag and drop icon" />
</RelativeLayout>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。



评论