0

我有两个用于同一个视图的翻译动画类,我现在想要的是我需要使用替代触摸来隐藏/显示视图。将只有一个动画放在一起时,我需要同时处理两个动画。这是我的代码。

ln.setOnTouchListener(new View.OnTouchListener() 
        {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) 
            {
                if(motionEvent.getAction() == MotionEvent.ACTION_DOWN)
                {
                    Animation animation = new TranslateAnimation(0,-200,0, 0);
                    animation.setDuration(2000);
                    animation.setFillAfter(true);
                    lv.startAnimation(animation);
                    lv.setVisibility(0);

                    }
                    else
                    {
                     Animation animation = new TranslateAnimation(-200,0,0, 0);
                        animation.setDuration(3000);
                        animation.setFillAfter(true);
                        lv.startAnimation(animation);
                      lv.setVisibility(0);

                }


                return true;
            }
        });
    }

我提到了这个,但我仍然面临这个问题。谁能告诉我如何解决这个问题。

4

1 回答 1

0

finally i found a solution to my problem. Here is the code.

layout.setOnTouchListener(new View.OnTouchListener() 
 {
     @Override
     public boolean onTouch(View view, MotionEvent motionEvent) 
     {
         if(motionEvent.getAction() == MotionEvent.ACTION_DOWN)
         {
            if(gone)
            {
                 Animation animation = new TranslateAnimation(-300,0,0, 0);
                 animation.setFillAfter(true);
                 animation.setDuration(500);
                 lv.setAnimation(animation);

                 gone = false;

            }
            else
            {
                 Animation animation = new TranslateAnimation(0,-300,0, 0);
              animation.setFillAfter(true);
              animation.setDuration(500);
                 lv.setAnimation(animation);
                 gone = true;
            }
         }
        return true;
     }
 });

and boolean gone = false; at the top.. Hope this will help some one :-)

于 2013-09-23T05:10:05.927 回答