涟漪效应在整行上不可见。

huangapple go评论80阅读模式
英文:

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?

   &lt;FrameLayout
        android:id=&quot;@+id/layout&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;64dp&quot;
        android:orientation=&quot;horizontal&quot;
        android:background=&quot;@android:color/white&quot;
        android:paddingLeft=&quot;@dimen/small_margin&quot;
        android:paddingRight=&quot;@dimen/small_margin&quot;&gt;

        &lt;CheckBox
            android:id=&quot;@+id/checkbox&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:layout_gravity=&quot;start|center_vertical&quot;
            android:checked=&quot;@{safeUnbox(viewModel.isEnabled), default=false}&quot;
            android:padding=&quot;@dimen/small_margin&quot;
            android:text=&quot;@={viewModel.abbreviation}&quot;
            android:textAppearance=&quot;@style/TextAppearance.Compat.Notification.Title&quot;
            tools:text=&quot;Bijbelvertaling&quot; /&gt;

        &lt;Space
            android:layout_width=&quot;0dp&quot;
            android:layout_height=&quot;0dp&quot;
            android:layout_weight=&quot;1&quot; /&gt;

        &lt;ImageView
            android:id=&quot;@+id/dragger&quot;
            android:layout_width=&quot;40dp&quot;
            android:background=&quot;?android:attr/selectableItemBackground&quot;
            android:layout_height=&quot;match_parent&quot;
            android:layout_gravity=&quot;center_vertical|end&quot;
            android:scaleType=&quot;center&quot;
            android:src=&quot;@drawable/ic_drag_handle_24px&quot;
            android:contentDescription=&quot;Drag and drop icon&quot; /&gt;
    &lt;/FrameLayout&gt;

涟漪效应在整行上不可见。

答案1

得分: 2

请使用以下代码替代FrameLayout,并将涟漪效果android:foreground=&quot;?android:attr/selectableItemBackground&quot;应用于根布局。

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

Output:
涟漪效应在整行上不可见。

英文:

Instead of FrameLayout use RelativeLayout like below and apply ripple effect android:foreground=&quot;?android:attr/selectableItemBackground&quot; to root layout.

&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:id=&quot;@+id/layout&quot;
    android:clickable=&quot;true&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;64dp&quot;
    android:orientation=&quot;horizontal&quot;
    android:foreground=&quot;?android:attr/selectableItemBackground&quot;
    android:background=&quot;@android:color/white&quot;
    android:paddingLeft=&quot;@dimen/small_margin&quot;
    android:paddingRight=&quot;@dimen/small_margin&quot;&gt;

    &lt;CheckBox
        android:id=&quot;@+id/checkbox&quot;
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:layout_alignParentLeft=&quot;true&quot;
        android:layout_centerVertical=&quot;true&quot;
        android:checked=&quot;@{safeUnbox(viewModel.isEnabled), default=false}&quot;
        android:padding=&quot;@dimen/small_margin&quot;
        android:text=&quot;@={viewModel.abbreviation}&quot;
        android:textAppearance=&quot;@style/TextAppearance.Compat.Notification.Title&quot;
        tools:text=&quot;Bijbelvertaling&quot; /&gt;

    &lt;ImageView
        android:id=&quot;@+id/dragger&quot;
        android:layout_width=&quot;40dp&quot;
        android:layout_height=&quot;match_parent&quot;
        android:layout_alignParentRight=&quot;true&quot;
        android:layout_centerVertical=&quot;true&quot;
        android:scaleType=&quot;center&quot;
        android:src=&quot;@drawable/ic_drag_handle_24px&quot;
        android:contentDescription=&quot;Drag and drop icon&quot; /&gt;

&lt;/RelativeLayout&gt;

Output:
涟漪效应在整行上不可见。

huangapple
  • 本文由 发表于 2020年1月6日 17:14:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609372.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定