0

I have my listview, with a text and a ImageButton near to it, should be on the right side in the future. I want to see a ripple effect when i touch on the text or white field. How can i do this?

At the moment, theres only a ripple effect when i touch the image button.

Thats my code for list_item, where i set up the layout for a row:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/text"
    android:elevation="2dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="15dp"
    android:textColor="@android:color/black"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:gravity="center_vertical"
    android:layout_centerVertical="true"
    android:layout_marginTop="40dp"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    />

<ImageButton
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/ic_delete_black_24dp"
    android:tint="#F44336"
    android:backgroundTint="@color/background"
    />


</RelativeLayout>

I found out, that i have to use a LinearLayout, but i dont know, how i have to use it correctly. My ListView looks like this:

<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:divider="#E0E0E0"
    android:dividerHeight="1dp"
    android:drawSelectorOnTop="true"
    >
    </ListView>

Here's a screenshot how it looks currently: When i press on the red image button on the right side, there will be a riplpe effect around it. In all other places i touch, is no ripple effect.

Any suggestions to fix? ^^ Thanks in advance

EDIT: I forgot to say, that the OnItemClickListerner from listview, doesnt work anymore, when i have defined the imagebutton

1 Answers1

0

As per my knowledge, Ripple is only shown to clickable views (ListView's row, Buttons or other clickable objects). As per material theory animation shown from those objects which responds (I don't think that TextView needs to respond on click). In your case TextView is not showing because simply it dosen't work normally but it works on buttons (ImageButton is Button).

If you still want this simply use one of these third partly libraries -

https://github.com/lgvalle/Material-Animations or https://github.com/balysv/material-ripple

Its the easiest way!

Sid
  • 13
  • 2
  • 12