I am trying to add touch feedback to LinearLayout, which is similar to the usual Button feedback at API level 21, as in this for example, and still have not been successful.
I defined a standard ripple like this:
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:colorControlHighlight"> <item android:id="@android:id/mask"> <shape android:shape="rectangle"> <solid android:color="?android:colorAccent" /> </shape> </item>
and used the StateListAnimator that Google provides here :
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:state_pressed="true"> <objectAnimator android:duration="@android:integer/config_shortAnimTime" android:propertyName="translationZ" android:valueTo="@dimen/touch_raise" android:valueType="floatType" /> </item> <item> <objectAnimator android:duration="@android:integer/config_shortAnimTime" android:propertyName="translationZ" android:valueTo="0dp" android:valueType="floatType" /> </item>
After defining the animator and ripples, I added them to LinearLayout like this:
<LinearLayout android:id="@+id/linearLayout" android:clickable="true" android:focusable="true" android:orientation="horizontal" android:background="@drawable/ripple" android:stateListAnimator="@anim/touch_elevation">
The idea is to use this LinearLayout as a button, since itโs much easier for me to insert various types of text and handle the positioning of the ImageView inside it (as opposed to button calls).
Adding a ripple effect or animation separately works if the background of the view does not have transparency on this .
I'm not sure if this is a problem related to the above question, but, seeing that the standard button allows you to use feedback with the excitement and height of the animation, I believe that achieving this effect is possible for other views as well.
Any understanding of this problem would be greatly appreciated.