2016-12-30 67 views
3

我正在爲我的項目使用rippleeffect library。但在Android Nougat and Marshmallow,應用崩潰由於這個庫:java.lang.IllegalStateException:恢復時下溢 - 更多恢復比保存

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(R ippleView.java:170) ........................ .................. ......

只要下面的鏈接這是一個已知的問題。 https://github.com/traex/RippleEffect/issues/76,我也嘗試了很多從stackoverflow的解決方案,但運氣確實有利於迄今!

可以做些什麼來解決這個問題?

+0

我想你可以通過降級修復這個錯誤 - targetSdkVersion至22,但我不建議使用!您不需要庫來使用漣漪效應 –

+0

此問題出現在Android API Level 23(Marshmallow)中。我更新了庫版本到最新版本。他們已經解決了這個錯誤。 –

回答

9

我面臨着同樣的問題,並沒有發現that.But如果

  • 降級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); 

如果你想定製的連鎖反應到視圖, 你需要創建一個新的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> 

如何使用: 要將紋波XML文件附加到任何觀點,將其設置爲背景如下: 假設你的紋波文件被命名爲my_ripple.xml。在exmple 1,2或3

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

'com.github.emanzanoaxa:RippleEffect:52ea2a0ab6'依賴爲我工作。 –

+0

@Saidur拉赫曼祝你好運:) –