Android: Animation Position Resets After Complete

后端 未结 9 1540
南笙
南笙 2020-11-27 13:30

I\'m using an xml defined animation to slide a view off the screen. The problem is, as soon as the animation completes it resets to its original position. I need to know how

9条回答
  •  我在风中等你
    2020-11-27 13:44

    This problem has bothered for more than a week. And Muhammad's answer pointed me a strightforward way to solve it.

    I used sever layout to implement side menus with animation. "view.layout will not be persistent. You should use LayoutParams, which will be persistent."

    Here's my solution: (Use what kind of LayoutParameter is depended on your own parent's layout):

    @Override
    public void onAnimationEnd(Animation animation) {
    FrameLayout.LayoutParams layoutParams=new FrameLayout.LayoutParams(screenWidth, screenHeight);
    layoutParams.setMargins((int) -(screenWidth * RATE), 0,
                (int) (screenWidth - screenWidth * RATE), screenHeight);
        for(View v:views) {
    
            v.setLayoutParams(layoutParams);
            //v.layout((int) -(screenWidth * RATE), 0, (int) (screenWidth - screenWidth * RATE), screenHeight);
            v.clearAnimation();
        }
    }
    

提交回复
热议问题