danb danb - 2 months ago 11
Android Question

create touch ripples unconstrained by parent view

I have an

android.support.v7.widget.AppCompatCheckBox
in a
RelativeLayout
. I get touch ripples, but they are constrained by the relative layout. Is there a simple way to have the ripples overflow the parent? (this is using appcompat 22.1.1)

enter image description here

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:visibility="invisible"/>

<android.support.v7.widget.AppCompatTextView
android:id="@+id/label"
android:layout_toRightOf="@id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Checkbox"/>

</RelativeLayout>


update removed the background on the RelativeLayout, it was irrelevant to the actual issue at hand. The behavior is the same.

Answer

You can try this:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackgroundBorderless">

(note the 'Borderless' suffix)

EDIT 1:

Another idea is to allow the parent view group to override its children's clipping: android:clipChildren="false" (android:clipToPadding="false")