在整行上看不到波纹效果

时间:2020-01-06 09:14:06

标签: android rippledrawable

我有一个RecyclerView,该行的右边带有一个选中标记和一个拖放(重新排列)图标。就像在official material design video中一样,我希望波纹效果能覆盖整行。但是当我跨过ImageView时,CheckBox不再可单击。这有可能吗?

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

enter image description here

1 个答案:

答案 0 :(得分:2)

代替FrameLayout像下面那样使用RelativeLayout并将波纹效果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>

输出: enter image description here