Pruthviraj
Pruthviraj

Reputation: 578

Ripple effect on Recyclerview items is not noticeable sometime

I have a recyclerview implementation in one of the activity and Recyclerview item click navigates to a different screen. But when user clicks on an Recyclerview item user can see ripple effect (in API level >= 21) before it navigates to other activity. My problem is some time navigation is fast and user couldn't able to notice any ripple effect. How can I delay navigation for some milliseconds so that user can see some ripple effect.

Recyclerview Layout is as follows

<android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/white"
                    android:focusable="true"
                    android:clickable="true"
                    android:foreground="?android:attr/selectableItemBackground"
                    android:clipToPadding="false"/>

Recyclerview Item Layout is as follows

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:clickable="true"
    android:focusable="true"
    android:background="?android:attr/selectableItemBackground"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <!--  ListRow Left sied Thumbnail image -->
    <LinearLayout
        android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/pad_3dp"
        android:orientation="vertical"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="@dimen/pad_5dp">

        <com.unvired.shout.util.CircularImageView
            android:id="@+id/thumbnail_image"
            android:layout_width="@dimen/pad_50dp"
            android:layout_height="@dimen/pad_50dp"
            app:border_color="?attr/colorPrimary"
            app:border_width="@dimen/pad_2dp"
            app:shadow="true" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:layout_width="@dimen/pad_20dp"
                android:layout_height="@dimen/pad_15dp"
                android:id="@+id/chat_red_image"
                android:layout_centerVertical="true" />

            <ImageView
                android:layout_width="@dimen/pad_20dp"
                android:layout_height="@dimen/pad_20dp"
                android:layout_marginLeft="@dimen/pad_5dp"
                android:id="@+id/chat_reply_image"
                android:layout_centerVertical="true" />
        </LinearLayout>
    </LinearLayout>

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/thumbnail"
        android:layout_toRightOf="@+id/thumbnail"
        android:text="Rihanna Love the way lie"
        android:layout_marginTop="@dimen/pad_5dp"
        android:textColor="#040404"
        android:typeface="sans"
        android:textSize="@dimen/txt_15sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/feed_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/name"
        android:textColor="#343434"
        android:textSize="@dimen/txt_12sp"
        android:layout_marginTop="1dip"
        android:layout_toRightOf="@+id/thumbnail"
        android:text="Just gona stand there and ..." />

    <TextView
        android:id="@+id/time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:layout_alignParentRight="true"
        android:text="5:45"
        android:textSize="@dimen/txt_12sp"
        android:textColor="?attr/colorPrimary"
        android:layout_marginRight="@dimen/pad_5dp"
        android:layout_marginTop="@dimen/pad_5dp"
        android:textStyle="bold" />


    <ImageView
        android:layout_width="@dimen/pad_30dp"
        android:layout_height="@dimen/pad_30dp"
        android:id="@+id/conversation_indicator"
        android:src="@drawable/link"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true" />
</RelativeLayout>

Upvotes: 3

Views: 1804

Answers (1)

Himanshu Likhyani
Himanshu Likhyani

Reputation: 4580

You may like to defer starting your new activity/fragment by a few milliseconds like this

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    @Override
    public void run() {
        startActivity(...)  // For starting an activity

        // Or for doing a fragment transaction
        // fragmentTransaction.commit();
    }
}, 250);

Upvotes: 4

Related Questions