Android - Making translations and objectAnimator on the same XML file

我的梦境 提交于 2019-11-29 04:23:49

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:

<!-- Rotate. -->
<objectAnimator
    android:duration="@integer/card_flip_time_full"
    android:interpolator="@android:interpolator/accelerate_decelerate"
    android:propertyName="rotateLeftRightIn"
    android:valueFrom="@integer/card_flip_rotation_off"
    android:valueTo="0" 
    android:valueType="intType"/>

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 ^^

Jawnnypoo

An alternative to the answer accepted, you could define an animator set, as seen here:

  <item android:state_pressed="true">
    <set>
      <objectAnimator android:propertyName="translationZ"
        android:duration="100"
        android:valueTo="2"
        android:valueType="floatType"/>
        <!-- you could have other objectAnimator elements
             here for "x" and "y", or other properties -->
    </set>   
  </item>   

  <item android:state_enabled="true"
    android:state_pressed="false"
    android:state_focused="true">
    <set>
      <objectAnimator android:propertyName="translationZ"
        android:duration="100"
        android:valueTo="2"
        android:valueType="floatType"/>
    </set> 
  </item> 

How to use StateListAnimator?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!