英文:
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附加的当前图像资源?
英文:
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?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论