Comparing resources within two drawables

后端 未结 1 995
再見小時候
再見小時候 2020-12-03 23:49

I am trying to compare two drawables but without success. I did some research, there is even a similar question but did not help.

In my app, I use getCompoundD

相关标签:
1条回答
  • 2020-12-03 23:56

    getConstantState doesn't work well

    If you do this: if(drawable1 == drawable2){

    you are comparing the reference of the objects and it not correct...

    use instead equals with the getConstantState() method...

    Update Try to compare with bytes or pixel is the only way that generally works.

     // Usage: 
     drawable1.bytesEqualTo(drawable2) 
     drawable1.pixelsEqualTo(drawable2) 
     bitmap1.bytesEqualTo(bitmap1) 
     bitmap1.pixelsEqualTo(bitmap2) 
    

    https://gist.github.com/XinyueZ/3cca89416a1e443f914ed37f80ed59f2

    0 讨论(0)
提交回复
热议问题