How a Translate Animation works: Android

后端 未结 1 719
小鲜肉
小鲜肉 2021-01-06 10:41

I\'m trying to move a RelativeLayout using TranslateAnimation. Code I have written for performing the same is:

translateAnimation =         


        
相关标签:
1条回答
  • 2021-01-06 11:28

    The 3rd parameter of the TranslateAnimation constructor you are using is a delta value, so the starting point is calculated like:

    currentYPos + startingDeltaY

    Since you seem to be passing in a Y value that refers to the location of something on the screen, this delta value won't be correct.

    Try using this constructor:

    public TranslateAnimation (int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)

    Like this:

    new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.ABSOLUTE, heightOfRootView-excuseContainer.getHeight(), Animation.ABSOLUTE, currentYPoint);
    
    0 讨论(0)
提交回复
热议问题