1

I have implemented the ripple effect for each item inside the ListView by using <ripple> element. I got the desired ripple effect when I touch (select) on each item in the ListView. But when I scroll the ListView and then select any item again the ripple disappears very fast (almost unnoticeable). I don't know why the ripple appears nicely on some ListView items and very weird on some.

My customized ripple layout is shown below (ripple_background.xml)

<ripple
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/light_black_overlay">
    <item>
        <shape
            android:shape="rectangle">
            <solid android:color="@android:color/background_light" />
        </shape>
    </item>
</ripple>

Layout for the item inside ListView

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="48dp"
    android:minHeight="?android:listPreferredItemHeight"
    android:orientation="horizontal"
    android:background="@drawable/ripple_background"> <!--My ripple layout-->

    <TextView
        android:id="@+id/someText
        android... />

    <ImageView
        android:id="@+id/someImage
        android... />

</RelativeLayout>

Has anyone faced this kind of weird ripple effect inside your ListView? Any idea if the ListView's recycling mechanism has to do something with this? Thank you.

Prudhvi
  • 2,276
  • 7
  • 34
  • 54

1 Answers1

1

Instead of passing ripple effect to each item of your list try this:

<ListView
        android:id="@+id/yourListView"
        ...
        android:listSelector="@drawable/ripple_background" />
Saeed Masoumi
  • 8,746
  • 7
  • 57
  • 76
  • Thanks Saeed, this worked for me. But do you have any idea why it's not working if I use the ripple background for each item inside the listview? – Prudhvi Aug 19 '15 at 19:02
  • Actually there is a way that ripple works for each item, i'm not sure but i think you should create a custom adapter and while you're binding view check whether item needs to show ripple or not(by storing state of each item) and some other handling like that. – Saeed Masoumi Aug 19 '15 at 19:11