我正在使用rippleeffect library
作为我的项目。但是在Android Nougat and Marshmallow
,由于这个库,App崩溃了:
compile 'com.github.traex.rippleeffect:library:1.3'
错误消息是:
致命异常:主要进程:com.test.testapp,PID:17713 java.lang.IllegalStateException:恢复中的下溢 - 比android.graphics.Canvas.restore上的android.graphics.Canvas.native_restore(Native Method)中的保存更多恢复( Canvas.java:522)at com.andexert.library.RippleView.draw(RippleView.java:170) ........................ ... .....................
就以下链接而言,这是一个已知问题。 https://github.com/traex/RippleEffect/issues/76和我也尝试过stackoverflow的很多解决方案,但到目前为止运气确实有利!
可以做些什么来解决这个问题?
我遇到了同样的问题,并没有找到一个好的解决方案。但如果你
targetSdkVersion
降级到22你可以运行它:意味着它不会崩溃!但我真的不建议这样做。'com.github.emanzanoaxa:RippleEffect:52ea2a0ab6'
canvas.save();
之前调用restore()
是您链接的另一个建议,因为您可以尝试https://codeload.github.com/traex/RippleEffect/zip/master(从您提供的链接中,有人尝试使用它们的解决方案)
或者我建议你自己创建它们根本不需要库!
Ripple
触摸效果在Android 5.0(API级别21)中引入,动画由新的RippleDrawable
类实现。
一般情况下,常规按钮的涟漪效果在API 21中默认工作,对于其他可触摸视图,可以通过指定:
android:background="?attr/selectItemBackground"
对于视图中包含的涟漪或:
android:background="?attr/selectItemBackgroundBorderless"
对于超出视图范围的涟漪。
您可以使用以下代码实现相同的功能:
int[] attrs = new int[]{R.attr.selectItemBackground};
TypedArray typedArray = getActivity().obtainStyledAttributes(attrs);
int backgroundResource = typedArray.getResourceId(0, 0);
myView.setBackgroundResource(backgroundResource);
如果要将涟漪效果自定义到视图中,则需要在drawable目录中创建新的XML
文件。
例子:
例1:无界波纹
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ffff0000" />
示例2:具有蒙版和背景颜色的波纹
<ripple android:color="#7777666"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/mask"
android:drawable="#ffff00" />
<item android:drawable="@android:color/white"/>
</ripple>
示例3:可绘制资源顶部的波纹
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ff0000ff">
<item android:drawable="@drawable/my_drawable" />
</ripple>
如何使用:要将ripple xml文件附加到任何视图,请将其设置为背景,如下所示:假设您的ripple文件名为my_ripple.xml
。例如1,2或3
<View
android:id="@+id/myViewId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/my_ripple" />
他们修复了这个错误:P RippleEffect