![](/img/trans.png)
[英]How to get the image resource of images added dynamically onto 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.