如何检查在Android的图片视图中设置了哪个图片?

问题描述

我正在开发一个应用程序,它具有多个图像视图和多个图像。我想检查哪个图像设置在一个图像视图上,并且我想将同一图像放入另一个图像视图中。 该应用程序有多个图像。如何才能以编程方式(特别是JAVA)实现此功能

解决方法

您可以将tag添加到ImageView

xml中或动态设置标签 在xml中:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageview" 
    android:background="@drawable/drawable_name"
    android:tag="drawable_name"/>

动态地

ImageView imageView=(ImageView)findViewById(R.id.imageview);
imageView.setTag("bg");

使用imageView.getTag()检索图像信息。

String backgroundImageName = String.valueOf(imageView.getTag()); 

您可以在更改可绘制对象并通过此方法获取它时设置标签

您可以看到这些问题以了解其他想法

How to check which current image resource is attached to ImageView in android xml?

How to check which image is linked to ImageView in android?