0

I have 3 RecyclerViews.

Z item belongs to Y. Y belongs to X.

Let's say there are A and B.

A Item layout looks like that.

<LinearLayout
            android:id="@+id/ll_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:clickable="true"
            style="@style/SelectableItemBackground"
            android:weightSum="3"
            android:focusable="true">

        <TextView
                android:id="@+id/tv1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:gravity="center"
                android:text="1"
                android:textAllCaps="true"
                android:textColor="@android:color/black" />

        <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rcv_b_list"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:clickable="true"
                android:focusable="true"
                android:paddingBottom="5dp"
                android:textAllCaps="true"
                android:textColor="@android:color/black"
                app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                tools:listitem="@layout/item_label" />
</LinearLayout>

B Item layout looks like this.

<LinearLayout
            android:id="@+id/ll_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:clickable="true"
            style="@style/SelectableItemBackground"
            android:weightSum="3"
            android:focusable="true">

        <TextView
                android:id="@+id/tv1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:gravity="center"
                android:text="1"
                android:textAllCaps="true"
                android:textColor="@android:color/black" />

        <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rcv_c_list"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:clickable="true"
                android:focusable="true"
                android:paddingBottom="5dp"
                android:textAllCaps="true"
                android:textColor="@android:color/black"
                app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                tools:listitem="@layout/item_label" />
</LinearLayout>

When I touch A Item, It has ripple effect. However, B Items doesn't get the effect. So, only non-B Items area has the ripple effect. When I touch B items area, only one B item has the ripple effect.

I'd like to implement ripple effect as one which follows the parent view behaviour(A List). When I touch any part of A item, I hope it gets ripple effect include all the child views. Also, vice-versa, When I touch any items of B list, while that A Item have the ripple effect and also, it clicks only A item. Not B item.

Now, I have 3 RecyclerViews. X, Y, Z. And I'd like to touch each Y item. And Z is not clickable.

How can I implement this feature?

c-an
  • 3,543
  • 5
  • 35
  • 82

1 Answers1

0

You may use

android:foreground="?attr/selectableItemBackground"
android:clickable="true"

to the parent view of your Item layout.

P.S: You may also set it to :background tag. Also you may use it with a android prefx like

android:background="?android:attr/selectableItemBackground"

You may apply whatever suits you or works for you.

Hamza Ahmed Khan
  • 476
  • 5
  • 19