Android why am I having double ripple effect on background selector?

2.5k views Asked by At

I am having a double ripple effect on press item(a ripple effect from center of the item and a second from the point touched), here is a screenshot of my problem:

enter image description here

But this only happen on the first item, in the others the ripple effect works well. I am following this udacity project and I did realize that they have the same problem.

Here are my resources I am using:

drawable-v21/touch_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

  <item android:state_pressed="true">
      <ripple android:color="@color/grey" />
  </item>

  <item android:drawable="@color/light_blue" android:state_activated="true" />

  <item android:drawable="@android:color/transparent" />
</selector>

row_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/touch_selector"
  android:minHeight="?android:attr/listPreferredItemHeight"
  android:orientation="horizontal">
  ...
</LinearLayout>

fragment_main.xml

...
<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="@null"
    tools:listitem="@layout/row_item" />
...

How can I fix this double ripple effect on item pressed? (Again, this just happen in the first item, the others work well).

Here is the source code: https://github.com/epool/SpotifyStreamer/tree/stage-2

3

There are 3 answers

4
Felipe On

@epool,

I downloaded your project and ran it. The problem occurred not only on the first item of the list, but on others as well. I did notice that it was inconsistent though, it didn't happen every single time.

It seems like you might have set the ripple effect, or at least enabled it, on a different place as well.

If you simply delete the line of code below, it should work just fine! =]

<item android:state_pressed="true">
   <ripple android:color="@color/grey" />
</item>

Just on a side note, I clicked multiple times on different items of the list to see how they would behave, and by doing that, I got the following error:

java.lang.ArrayIndexOutOfBoundsException: src.length=2048 srcPos=2048 dst.length=2048 dstPos=0 length=2047

That's on your Binder.java file, on line 446. So you might want to address that.

If you have any other question, please let me know.

0
Sid Go On

I had also the same problem, and after hunting for it for hours, I realized that the ripple effect is triggered twice because I put v.setEnabled(false) then v.setEnabled(true) inside the onClickListener to disable the view while the onClick is ongoing.

Removing them solved the problem for me.

0
Afilu On

I think the double ripple can be avoided if instead of setting the background on the list item, it is set as the listSelector on the list view itself, or not including the state_pressed in the item's background selector.