2013-08-23 38 views
2

我目前正在研究Galaxy S4應用程序,其中我想用移動手指移動圖像,但是如何實現這個onHoverListener。請幫忙。 並提前致謝。如何在android中移動圖像onHoverListener

+0

請使用拖放的http:// androidrox.wordpress.com/2011/05/13/android-sample-app-drag-and-drop-image-using-touch/ –

回答

0

而不是hoverListener實現你的圖像上的觸摸監聽器,並在你的活動中實現touchevent。那麼你可以使用OnTouchEvent的actionMove。

當用戶執行actionMove使用motionEvent對象查找座標並使用翻譯animation將這個視圖轉換爲那些座標時,這將使您看起來像移動圖像。

+0

在MotionEvent.Move中給出imageView的相同座標將導致圖像閃爍....在...上顯示2張圖片時間,即圖像與手指一起不平滑移動。 –

1

可以實現onTouchListener()您的ImageView象下面這樣:

img = ((ImageView) findViewById(R.id.img_arrow)); 

img.setOnTouchListener(new OnTouchListener() { 

      @Override 
      public boolean onTouch(View v, MotionEvent motionEvent) { 
       int rawX = (int) motionEvent.getX(); 
       int rawY = (int) motionEvent.getY(); 
       if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) { 
        TranslateAnimation anim = new TranslateAnimation(rawX, rawY, 0, 0); 
        anim.setDuration(500L); 
        img.startAnimation(anim); 
       } 
       return true; 
      } 
}); 

在這裏,我們正在申請TranslationAnimation我們的ImageView IMG