Android的translateanimation框架

时间:2013-09-08 12:58:07

标签: android animation

我对此指令TranslateAnimation有问题, 在实际操作中,当开始动画向后移动时(从rigth到左边的动画),剪切右侧的帧,只是在释放触摸屏时从屏幕中重新出现的部分... 相反,当我运行动画消失帧(从左到右)时..例如:

将手指拖到屏幕中间,最后释放..动画开始,帧消失..故障: 如果我再次在屏幕中间点到屏幕中再次按下它,则动画从我按下的点开始

我的代码:

            RelativeLayout.LayoutParams params = null;
         int x;
         int offset;
       int tmp= 0;
        int avviato = 0;
    @Override
    public boolean onTouch(View v, android.view.MotionEvent event) {
            // TODO Auto-generated method stub
            FrameLayout frame = (FrameLayout) this.findViewById(R.id.frame1);
            if(v == findViewById(R.id.frame1)){
            if(event.getAction() == android.view.MotionEvent.ACTION_MOVE){
                    x= (int) event.getRawX();
    if (tmp==0){
            offset = x;
            tmp = 1;
    }

    if(offset < (x - WHIDTH /5) || offset > (x + WHIDTH /5) || avviato ==1)
    {
            params = new RelativeLayout.LayoutParams((int) (WHIDTH ), (int) (HEIGHT));
            params.leftMargin = x;
            params.topMargin = (int) (0);
            frame.setLayoutParams(params);
            avviato = 1;
    }

                    }//fine get action
            if(event.getAction() == android.view.MotionEvent.ACTION_UP){
                    tmp = 0;
                    avviato = 0;

                    x= (int) event.getRawX();
                    if(x > (WHIDTH /3))
                    {

                    Animation  animation= new TranslateAnimation(x - x, WHIDTH , 0, 0);
                    animation.setDuration(1000);
                    animation.setFillAfter(true);
                    frame.startAnimation(animation);


                    }
                    if(x < (larghezza /3))
                    {
                            Log.i("xxXxxanommmm", toString().valueOf(x));
                            Animation animation= new TranslateAnimation(x-x,0 -x, 0, 0);
                            animation.setDuration(1000);
                            animation.setFillAfter(true);
                            frame.startAnimation(animation);

                    }
            }
            return true;
            }//fine if v

            return false;
    }//fine touch

0 个答案:

没有答案