如何实现对图像的触摸监听器? [英] How to implement touch listener on image?

查看:159
本文介绍了如何实现对图像的触摸监听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,在我的应用我使用的显示图像的ImageView 使用XML解析的网址,我想显示放大的图像,当我双触摸的图像,然后zoomImage再次双击触摸,我想重置image.How使用的Andorid图像落实

I am developing an application,In my application i am display images using ImageView from url using xml parsing,i want to display zoom image,when i double touch on the Image,then again double touch on zoomImage,i want to reset image.How to implement in image using andorid

感谢所有

推荐答案

这是如何实现的Andr​​oid触摸监听器。

This is how you implement a touch listener in Android.

        yourImageView.setOnTouchListener(new OnTouchListener()
        {

            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
                return false;
            }
       });

要检测双水龙头使用GestureDetector这样的:

To detect double taps you use GestureDetector like this:

1)使自己的GestureDetector,从SimpleOnGestureListener派生并重写你感兴趣的(见谷歌的SimpleOnGestureListener文档的确切的方法,你可以重写,我已经做了双在这里自来水)的方法:

1) Make your own GestureDetector, derived from SimpleOnGestureListener and override the methods you're interested in (see google's docs on SimpleOnGestureListener for the exact methods you can override, I've done double tap here):

class MyGestureDetector extends GestureDetector.SimpleOnGestureListener
{

@Override
 public boolean onDoubleTapEvent(MotionEvent e)
 {
    Log.i("Taghere..", "onDoubleTapEvent");
    return true;
    }
}

2)创建你的手势检测器的实例。我在做一个成员变量和实例中的onCreate。

2) Create an instance of your gesture detector. I'm making a member variable and instantiating in onCreate.

    private GestureDetector mDetector;

    mDetector = new GestureDetector(this, new MyGestureDetector());

3)安装在您的ImageView和路由信息到你的手势检测触摸监听器:

3) Setup a touch listener on your imageview and route the messages to your gesture detector:

ImageView iv = (ImageView)findViewById(R.id.yourimageviewid);
iv.setOnTouchListener(new OnTouchListener(){

@Override
public boolean onTouch(View v, MotionEvent event)
{
    mDetector.onTouchEvent(event);
    return true;
}});

我会覆盖MyGestureDetector的方法和登录的logcat像我做的双击得到的感觉是怎样工作的。

I would override the methods in MyGestureDetector and log to logcat like I'm doing on double tap to get a feel for how this works.

这篇关于如何实现对图像的触摸监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆