本文介绍了如何在Android的幻灯片图像用手指触摸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的,我想滑动的手指触摸图片Android应用程序。我已实施 onClickListener 与我的幻灯片图像,但我不知道如何实现手指触摸功能。

I am developing an android application in which I want to slide images with finger touch. I have implemented an onClickListener with which I can slide images but I don't know how to implement finger touch functionality.

请给我建议任何方法如何滑动的手指触摸图片。任何建议或任何教程或方法会有所帮助。

Please suggest me any method how to slide images with finger touch. Any Suggestion or any tutorial or method will be helpful.

推荐答案

您可以使用onTouchListner方法,而不是onClickListner。下面onTouchListners例说明。

You can use onTouchListner method instead of onClickListner. Below onTouchListners example is given..

public class abc extends Activity implements OnTouchListener
{
     ImageView img;
     protected void onCreate(Bundle savedInstanceState)
     {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.one);

                img = (ImageView) findViewById(R.id.imageView1);
                img.setOnTouchListener(this);
     }

        public boolean onTouch(View v, MotionEvent event)
    {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
            {
                  // Here u can write code which is executed after the user touch on the screen
                     break;
            }
            case MotionEvent.ACTION_UP:
            {
                   // Here u can write code which is executed after the user release the touch on the screen
                 break;
            }
            case MotionEvent.ACTION_MOVE:
            {
               // Here u can write code which is executed when user move the finger on the screen
                break;
            }
        }
        return true;
    }

这篇关于如何在Android的幻灯片图像用手指触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 07:32