Android - Making translations and objectAnimator on the same XML file

前端 未结 2 1767
清歌不尽
清歌不尽 2020-12-16 22:52

I\'ve been trying to make a 3D Cube rotation effect while sliding from one fragment to another. First i was using a translate effect (on XML) calling with FragmentTran

2条回答
  •  眼角桃花
    2020-12-16 23:20

    Solved the problem by creating my own methods on the extended FrameLayout. Here's the code from the extended FrameLayout:

    //Rotate from Left to Right turning visible
        public float getRotateLeftRightIn(){
            return getRotationY();
        }
        public void setRotateLeftRightIn(int rotateLeftRightIn){
            setPivotX(getWidth());
            setPivotY(getHeight()/2);
            setRotationY(rotateLeftRightIn);
        }
    

    And on the XML:

    
    
    

    In this case, @integer/card_flip_time_full stands for the duration of the entire animation and @integer/card_flip_rotation_off stands for the degrees (in this case -90%).

    After this, all I need to do to make this animation to work is, when starting the fragment, set the xml files in the custom animation

    transaction.setCustomAnimations(enter,exit,popEnter,popExit);
    

    Hope this can be useful to some one ^^

提交回复
热议问题