簡體   English   中英

如何動態獲取並比較android中兩個圖像的圖像資源?

[英]How to get and compare the image resources of two images in android dynamically?

我需要比較兩個ImageViews的圖像資源並顯示它們是否匹配。 我已經嘗試了解決stackoverflow中類似問題的解決方案,但它們導致我的應用程序崩潰。 剛剛提到我已經使用setImageResource設置圖像,所以請發布不需要我刪除setImageResource方法的解決方案

您可以像這樣在kotlin中比較imageViews:

if(imageView1.drawable.constantState == imageView2.drawable.constantState){
//Do something
}

或者,如果您喜歡使用Java:

if(imageView1.getDrawable().getConstantState() == imageView2.getDrawable().getConstantState()){
//Do something
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM