【问题标题】:How to check which image is set on an image view in Android? [duplicate]如何检查在 Android 的图像视图上设置了哪个图像? [复制]
【发布时间】:2020-08-14 04:53:08
【问题描述】:

我正在开发一个应用程序,它有多个图像视图和多个图像。我想检查在图像视图上设置了哪个图像,并且我想将相同的图像放在另一个图像视图中。 该应用程序有多个图像。我如何以编程方式实现这一点,特别是 JAVA。

【问题讨论】:

标签: java android imageview


【解决方案1】:

您可以将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()); 

你可以在你改变你的drawable的时候设置tag并通过这个方法获取它

您可以查看这些问题以获得其他想法

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?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 2019-07-19
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多