2011-05-07 47 views
1

我不知道如何做一个简单的onFling只需开始一个动画。不管滑动的方向是什么方向,滑动屏幕都会导致动画开始。我想知道的另一件事是如何让它通过动画,当动画完成时,我希望它显示一张图片。给你一个想法,我在做什么图片扭曲旋转板。动画是纺纱机旋转,纺纱完成后停止并指向一个方向。我怎样才能得到类似的效果。 (动画是一个旋转的动画和图片都指向不同的方向)关于导致一个简单的动画的投掷

希望任何人都可以给的帮助。谢谢。

回答

1

一种可能性:使用一个手势检测器来检测这个投影。

伪代码:

public class WhatEver extends Activity implements OnGestureListener { 
private GestureDetector gestures; 
protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
gestures = new GestureDetector(mContext, this); 
View yourViewYouWantToHaveThemFling=(View) findViewById(blah..); 
yourViewYouWantToHaveThemFling.setOnTouchListener(new OnTouchListener() { 

       @Override 
       public boolean onTouch(View arg0, MotionEvent event) { 

        if (gestures.onTouchEvent(event)) { 
         return true; 
        } 
        return false; 
       } 

      }); 

} 
//all your normal stuff 
@Override 
    public boolean onDown(MotionEvent e) { 

     return true; //must return true to continue 
    } 

    @Override 
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, 
      float velocityY) { 
//do something 
     return false; 
    } 

    @Override 
    public void onLongPress(MotionEvent e) { 

    } 

    @Override 
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, 

      float distanceY) { 

     return false; 
    } 

    @Override 
    public void onShowPress(MotionEvent e) { 

    } 

    @Override 
    public boolean onSingleTapUp(MotionEvent e) { 

     return false; 
    } 
} 

为动画,设置监听你的动画,

yourAnimation.setAnimationListener(new DisplayPicture()); 

然后

private final class DisplayPicture implements Animation.AnimationListener { 
. 
. 

public void onAnimationEnd(Animation animation) { 
      //code to display your picture here 
     } 
. 
. 
} 
+0

感谢,这是一个很大的帮助。 – Steven 2011-05-07 00:39:17

+0

您可以将其标记为已接受;) – jkhouw1 2011-05-07 02:31:27