implement GestureDetector for an ImageView

后端 未结 2 1952
一个人的身影
一个人的身影 2021-01-06 14:37

Good moorning :

I have an ImageView in my Activity and I setted the OntOuchListner() to my ImageView, which means that I implemented that interface for my I

相关标签:
2条回答
  • 2021-01-06 14:47

    Yes you can do it. Have a class extends ImageView and implements OnGestureListener.

    0 讨论(0)
  • 2021-01-06 15:08
    public class TestImageView extends ImageView  implements OnGestureListener{
        public TestImageView(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
    
            setOnTouchListener(new View.OnTouchListener() {
    
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // TODO Auto-ge`enter code here`nerated method stub
                    return false;
                }
            });
        }
    
        @Override
        public boolean onDown(MotionEvent e) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                float velocityY) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public void onLongPress(MotionEvent e) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
                float distanceY) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public void onShowPress(MotionEvent e) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            // TODO Auto-generated method stub
            return false;
        }
    }
    

    Now you can use TestImageView in your xml instead of just ImageView.

    0 讨论(0)
提交回复
热议问题