How to slide image with finger touch in android?

前端 未结 5 1743
迷失自我
迷失自我 2021-01-31 06:19

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

5条回答
  •  感情败类
    2021-01-31 07:05

    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;
        }
    

提交回复
热议问题