Android的动画错误 [英] Android Animation bug

查看:114
本文介绍了Android的动画错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,当我点击它,它就会去做它滑动右侧小有一点位和在那里停留的第一个动画,然后它会自动做第二次动画和滑回

这是它应该如何去

您点击它,它会向右侧滑动。当你再次点击它就会返回滑向左侧。

我的code:

 公共无效侧边栏()
   {       ImageView的侧边栏=(ImageView的)findViewById(R.id.sidebar);       如果(出== 0)
       {
       mSlideInRight = AnimationUtils.loadAnimation(这一点,R.anim.slide_in_right);
       mSlideInRight.setFillAfter(真);
       sidebar.startAnimation(mSlideInRight);
       出= 1;
       }       如果(出== 1)
       {
               mSlideInLeft = AnimationUtils.loadAnimation(这一点,R.anim.slide_in_left);
               sidebar.startAnimation(mSlideInLeft);
               出= 0;
       }   }

这部分是在哪里,当你点击它,它处理

 公共无效的onClick(视图v){        开关(v.getId())
        {
            案例R.id.sidebar:
                侧边栏();
            打破;
        }    }


解决方案

更改

 如果(出== 1)

条件

 否则,如果(出== 1)

在它的当前形式下,code将在完成后的第一个执行的第二块。毕竟,你只是明确地设置 OUT = 1

So, When I click on it it will go do the first animation which is sliding the right alittle bit and staying there and then it will AUTO do the second animation and slide back

This is how its SUPPOSED TO GO

You click on it and it will slide to the right. And when you click on it again it will slide BACK to the left.

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;
       }

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

   }

This part is where it handles when you click on it

public void onClick(View v) {

        switch(v.getId())
        {


            case R.id.sidebar:
                sideBar();
            break;
        }



    }

解决方案

Change your

if (out == 1)

condition to

else if (out == 1)

In it's current form, the code will execute the second block after finishing the first. After all, you just explicitly set out = 1.

这篇关于Android的动画错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆