0

那么,这是我的问题吗?我有它会滑出的地方,然后它会停留在那个位置,然后你应该能够再次点击它,它会滑回原来的位置。

但相反,我必须点击它 FIRST 所在的位置。即使它滑出。我想在动画之后制作它,我可以在任何地方单击它,它会滑出。

这是我的代码

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

   }

这是您单击它时的代码

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

    }
4

1 回答 1

0

动画仅影响侧边栏ImageView的绘制方式,而不影响其实际位置。动画完成后,您应该将侧边栏的布局参数更新到您想要的位置。如果您AnimationListener希望在动画运行时或完成后更新位置,或者startAnimation如果您希望在动画开始时发生位置更改,则可以在调用后立即执行此操作。

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

替换RelativeLayout为您的 ImageView 是子级的任何布局。

于 2012-10-24T00:42:56.390 回答