简体   繁体   English

Image View OnTouchListener无法正常工作?

[英]Image View OnTouchListener not working properly?

Hi I have loaded dynamically images in different position using single image view instance. 嗨,我已经使用单个图像视图实例在不同位置动态加载了图像。 my problem is if I touch particular image second image also affected 1st I wish to find which image is touched. 我的问题是,如果我触摸特定的图像,第二个图像也影响了第一个图像,那么我想找到被触摸的图像。 i want to print which image is touched. 我想打印被触摸的图像。 I am suffer in this task please help me. 我在这项任务中受苦,请帮助我。

my problem is i have only one imageview to show all images in appropriate location. 我的问题是我只有一个imageview在适当的位置显示所有图像。 I received xml file that xml contain everything like image size, image position ...etc I am loading dynamically images because i receive xml file dynamically. 我收到了xml文件,其中xml包含图像大小,图像位置...等所有内容,我正在动态加载图像,因为我动态接收到xml文件。 if i touch one image i wish to identify which image is clicked in the design that's all 如果我触摸一张图片,我希望确定在设计中单击了哪张图片

This is my screen shot: 这是我的屏幕截图: 在此处输入图片说明

Firtly implements onTouchListener then override the method, 首先实现onTouchListener,然后覆盖该方法,

ImageView one = ....
ImageView two = ....
one.SetTag("ITEM ONE");
two.SetTag("ITEM TWO");

one.setOnTouchListener(this);
two.setOnToucListener(this);

@Override
public boolean onTouch(View v, MotionEvent event) {

    if(v == one)
    {
       Log.e("Touched Itemd: ",(String) v.getTag().toString());
    }
    if(v == two)
    {
       Log.e("Touched Itemd: ",(String) v.getTag().toString());
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM