0

I'm implementing an Animation for one menu in my project.

The animation itself is ok, the menu enters and exit just as I wanted: Slide from left to right and right to left, however...

If the entire view is OUT of the screen, then it NEVER comes back egain! If, at least one pixel is still inside the screen, then it comes back normally.

I belive that Android is disposing the layout, and not caring about it after out of the screen bounds. I tried to place a setVisibility(VISIBLE) but it also didn't worked.

Here is the code:

public class ChwaziMenuAnimation extends Animation{

        float posStart = 0;
        float posTarget = 100;

        int getCurrentPosition(){
            RelativeLayout.LayoutParams rootParam =
                    (RelativeLayout.LayoutParams) rootView.getLayoutParams();

            return rootParam.leftMargin;
        }

        public void setTarget(float target){
            // Save current position
            posStart = getCurrentPosition();
            posTarget = target;
        }

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            RelativeLayout.LayoutParams rootParam =
                    (RelativeLayout.LayoutParams) rootView.getLayoutParams();

            // Calculate current position
            rootParam.leftMargin = (int) ((posTarget - posStart) * interpolatedTime + posStart);

            rootView.setLayoutParams(rootParam);
        }

        /*
         *  Since we will be animating the margin, the bounds will always change 
         */
        public boolean willChangeBounds() {
            return true;
        };


    };

And how I initialize the animation:

public void appear(){

        Log.i(TAG, "appear");

        menuAnimation.setTarget(0);
        menuAnimation.setDuration(750);
        rootView.clearAnimation();
        rootView.startAnimation(menuAnimation);
    }

    public void disapear(){
        Log.i(TAG, "disapear");

        menuAnimation.setTarget(-400);
        menuAnimation.setDuration(750);
        rootView.startAnimation(menuAnimation);
    }
4

1 回答 1

0

我遇到了同样的问题,到目前为止,我的解决方法是将视图边界扩展到可显示区域上的至少一个像素,并使该部分透明。丑陋,但对我来说它似乎工作。

更奇怪的是:视图没有消失,当移出屏幕右侧时,只有当移出屏幕左侧时。但这可能取决于设备。

于 2013-11-08T11:37:22.877 回答