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

huangapple go评论86阅读模式
英文:

How to check which image is set on an image view in Android?

问题

I want to check, which image is set on an image view, and i want to put that same image in another image view.
The application is having multiple images. How can I implement this programmatically, specifically in JAVA.

英文:

I am developing an application and it is having multiple image views and multiple images. I want to check, which image is set on an image view, and i want to put that same image in an another image view.
The application is having multiple images. How can i implement this programatically, specifically JAVA.

答案1

得分: 0

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

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

您可以查看以下问题以获得其他想法:

如何在Android XML中检查ImageView附加的当前图像资源?

如何在Android中检查ImageView链接的图像?

英文:

You can add tag to ImageView,

Set a tag either in xml or dynamically
In 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"/>

Dynamically,

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

Use imageView.getTag() to retrieve image information.

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

you can set tag when you change your drawable and get it by this method

You can see these question to get some other idea

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?

huangapple
  • 本文由 发表于 2020年8月14日 12:53:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/63406752.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定