java.lang.IllegalStateException:还原下溢-还原多于保存 [英] java.lang.IllegalStateException: Underflow in restore - more restores than saves

查看:259
本文介绍了java.lang.IllegalStateException:还原下溢-还原多于保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为项目使用rippleeffect library.但是在Android Nougat and Marshmallow中,应用程序由于该库而崩溃:

I am using rippleeffect library for my project. But in Android Nougat and Marshmallow, App crashes due to this library:

compile 'com.github.traex.rippleeffect:library:1.3'

错误消息是:

致命异常:主要 流程:com.test.testapp,PID:17713 java.lang.IllegalStateException:还原下溢-还原多于保存 在android.graphics.Canvas.native_restore(本机方法) 在android.graphics.Canvas.restore(Canvas.java:522) 在com.andexert.library.RippleView.draw(RippleView.java:170) ........................... ........................

FATAL EXCEPTION: main Process: com.test.testapp, PID: 17713 java.lang.IllegalStateException: Underflow in restore - more restores than saves at android.graphics.Canvas.native_restore(Native Method) at android.graphics.Canvas.restore(Canvas.java:522) at com.andexert.library.RippleView.draw(RippleView.java:170) ........................ ........................

就下面的链接而言,这是一个已知问题. https://github.com/traex/RippleEffect/issues/76 ,我也尝试过到目前为止有很多来自stackoverflow的解决方案,但到目前为止运气还不错!

As far as the below link this is a known issue. https://github.com/traex/RippleEffect/issues/76 and I also tried so many solutions from stackoverflow but luck did favor so far!!!

如何解决此问题?

推荐答案

我遇到了同样的问题,但没有找到一个好的解决方案.但是,如果您

I faced the same issue and did not found a good solution for that.But If you

  • targetSdkVersion降级到22,您可以运行它:这意味着它不会崩溃!但我真的推荐.
  • 尝试使用编译此依赖项进行编译-> 'com.github.emanzanoaxa:RippleEffect:52ea2a0ab6'
  • 在每个restore()之前致电canvas.save();是链接中的另一个建议,因为您可以尝试
  • 您也可以尝试在项目中添加该库并使用它
  • Downgrade targetSdkVersion to 22 you can run it: meaning it does not crash! but I really don't recommend that.
  • Try to compile it with compile this dependency ->'com.github.emanzanoaxa:RippleEffect:52ea2a0ab6'
  • Call canvas.save(); before every restore() is another suggestion from your link given that you can try
  • You can also try to add that library inside your project and use it

https://codeload.github.com/traex/RippleEffect/zip/master (从您提供的链接中可以找到人们尝试使用的解决方案)

https://codeload.github.com/traex/RippleEffect/zip/master (from the link you provided there are solutions that people have tried use them)

或者我建议您自己创建它们,根本不需要任何库!

Or i suggest you to create them by yourself no libraries needed at all!

Ripple触摸效果是在Android 5.0(API级别21)中引入的,动画是通过新的RippleDrawable类实现的.

Ripple touch effect was introduced in Android 5.0 (API level 21) and the animation is implemented by the new RippleDrawable class.

API 21中默认情况下,常规按钮起作用的一般性波纹效果,对于其他可触摸视图,可以通过 specify 来实现:

General, ripple effect for regular buttons works by default in API 21 and for other touchable views, it can be achieved by specifying:

android:background="?attr/selectItemBackground"

查看视图中包含的波纹,或:

for ripples contained within the view or:

android:background="?attr/selectItemBackgroundBorderless"

表示超出视图范围的波纹.

for ripples that extend beyond the view's bounds.

您可以使用以下代码实现相同的目的:

You can achieve the same in code using:

int[] attrs = new int[]{R.attr.selectItemBackground};
TypedArray typedArray = getActivity().obtainStyledAttributes(attrs);
int backgroundResource = typedArray.getResourceId(0, 0);
myView.setBackgroundResource(backgroundResource);


如果您要自定义波纹效果到视图中, 您需要在drawable目录中创建一个新的XML文件.


If you want to customize the ripple effect into a view, you need to create a new XML file, inside the drawable directory.

示例:

示例1 :无限波动

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#ffff0000" />

示例2 :具有蒙版和背景色的波纹

Example 2: Ripple with mask and background color

<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 :在可绘制资源上方显示波纹

Example 3: Ripple on top a drawable resource

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#ff0000ff">
    <item android:drawable="@drawable/my_drawable" />
</ripple>

使用方法: 要将您的涟漪图xml文件附加到任何视图,请将其设置为背景,如下所示: 假设您的涟漪文件命名为my_ripple.xml.例如1、2或3

How to Use: To attach your ripple xml file to any view, set it as background as following: assuming your ripple file is named my_ripple.xml. in exmple 1, 2 or 3

<View 
    android:id="@+id/myViewId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/my_ripple" />

这篇关于java.lang.IllegalStateException:还原下溢-还原多于保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆