简体   繁体   English

动画向右移动后,Android Animation Bug不会让我单击

[英]Android Animation Bug wont let me click after animation move to the right

So, here's my problem? 那么,这是我的问题吗? I have it where it will slide out and then it will stay in that position and then you should be able to click on it again and it will slide back to the original location. 我将其放置在滑出的位置,然后将其保持在该位置,然后您应该能够再次单击它,然后它将滑回到原始位置。

But instead I have to click on where it FIRST was at. 但是相反,我必须单击“ FIRST”所在的位置。 Even when it's slided out. 即使滑出。 I want to make it after the animation I can click it any where, that it slided out. 我想在动画之后制作它,我可以在它滑出的任何位置单击它。

Here's my code 这是我的代码

   public void sideBar()
   {

       ImageView sidebar = (ImageView)findViewById(R.id.sidebar);

       if(out == 0)
       {
       mSlideInRight = AnimationUtils.loadAnimation(this, R.anim.slide_in_right);
       mSlideInRight.setFillAfter(true);
       sidebar.startAnimation(mSlideInRight);
       out= 1;
       }
       else if(out == 1)
       {
               mSlideInLeft = AnimationUtils.loadAnimation(this, R.anim.slide_in_left);
               sidebar.startAnimation(mSlideInLeft);
               out=0;
       }

   }

and this is the code for when you click on it 这是您单击它时的代码

public void onClick(View v) {
        ImageView sidebar = (ImageView)findViewById(R.id.sidebar);
         ImageView popup = (ImageView)findViewById(R.id.popup);
         ImageView popup2 = (ImageView)findViewById(R.id.popup2);

        switch(v.getId())
        {           
            case R.id.sidebar:
                sideBar();
            break;
        }

    }

Animations only affect how your sidebar ImageView is drawn, not its actual position. 动画只会影响侧边栏ImageView的绘制方式,而不影响其实际位置。 After your animation completes, you should update the sidebar's layout parameters to your desired position. 动画完成后,应将侧栏的布局参数更新到所需位置。 You can do this in an AnimationListener if you want the position to be updated as the animation runs or after it is complete, or right after your call to startAnimation if you want the position change to happen as the animation starts. 如果希望在动画运行时或动画完成后更新位置,或者希望在动画开始时发生位置更改,则在调用startAnimation之后立即更新位置,可以在AnimationListener执行此操作。

mSlideInRight.setAnimationListener(new AnimationListener() {
    @Override
    public void onAnimationStart(Animation anim) {};

    @Override
    public void onAnimationRepeat(Animation anim) {};

    @Override
    public void onAnimationEnd(Animation anim) {
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(...);
        // Set properties of layoutParams here
        sidebar.setLayoutParams(layoutParams);
    };
});

Replace RelativeLayout with whatever layout your ImageView is a child of. 更换RelativeLayout与任何布局您的ImageView是一个孩子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM