Android ImageView Click/Ripple Effect

Jul 20, 2019

Solution 1: Ripple Effect

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/yy_shop_mushroomhouse"
    android:padding="4dp"
    android:background="?attr/selectableItemBackgroundBorderless"
    android:clickable="true"
    />

or

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/yy_shop_mushroomhouse"
    android:padding="4dp"
    android:background="?attr/selectableItemBackgroundBorderless"
    />

NOTE: Using ?android:attr/selectableItemBackgroundBorderless require API 21

Solution 2: Selectable Effect

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/yy_shop_mushroomhouse"
    android:padding="4dp"
    android:background="?android:attr/selectableItemBackground"
    android:clickable="true"
    />

or

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/yy_shop_mushroomhouse"
    android:padding="4dp"
    android:background="?android:attr/selectableItemBackground"
    />

Solution 3: Button Effect

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/yy_shop_mushroomhouse"
    android:adjustViewBounds="true"
    style="?android:attr/borderlessButtonStyle"
    />

NOTE: The image is smaller due to added padding and margin.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.