我在LinearLayout (相当于一个按钮)上使用android:background="?attr/selectableItemBackground"来获得连锁反应效果。单击此button时,当前活动会在过渡期间向左滑动。问题是,涟漪效应需要一段时间才能触发,当它变得可见时,活动转换已经开始,这使得使用触摸反馈完全无用。我不想在活动转换中添加延迟,这将是愚蠢的。
XML文件如下所示:
<android.support.v7.widget.CardView>
<LinearLayout
android:clickable="true"
android:background="?attr/selectableItemBackground"/>
</android.support.v7.widget.CardView>如何才能使涟漪效果变得有用和可见?
发布于 2017-11-01 21:22:44
尝试使用自己的drawable作为背景:
<android.support.v7.widget.CardView>
<LinearLayout
android:clickable="true"
android:background="@drawable/ripple"/>
</android.support.v7.widget.CardView>和ripple.xml:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#80585554">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#your color"/>
</shape>
</item>
</ripple>发布于 2017-11-01 21:10:23
在CardView上,您可以应用
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:foreground="?attr/selectableItemBackground"
android:clickable="true">
<!--linearlayout etc...-->
</android.support.v7.widget.CardView>发布于 2020-07-30 23:01:48
如果视图的父级之一在shouldDelayChildPressedState方法中返回true,则按下状态会延迟。通常,不滚动的ViewGroup的子类应该重写此方法并返回false。
https://stackoverflow.com/questions/47055491
复制相似问题