Android animation - initial view state

I have one Animation, which causes the view to shift from the screen to the right, this works as expected with the following code:

Animation outtoRight = new TranslateAnimation(
         Animation.RELATIVE_TO_SELF,  0.0f, Animation.RELATIVE_TO_SELF,  +1.0f,
         Animation.RELATIVE_TO_SELF,  0.0f, Animation.RELATIVE_TO_SELF,   0.0f
        );
outtoRight.setDuration(500);
outtoRight.setInterpolator(new AccelerateInterpolator());
outtoRight.setFillAfter(true);

This means that the view to which I am applying this animation will exit the screen perfectly. Of course, I have the opposite. But my question is, how can I display the view on the screen so that I can insert it without applying this animation to it at least once?

I played with negative fields and such, but I cannot find the correct properties for my view to be off screen at startup.

Just to clarify, I can hide it from the very beginning with a different animation, but I see that it goes away, even if it is for a split second. There must be a way so that he simply was not there at the beginning and allowed me to push it later.

+3
source share
5 answers

I am not an animation specialist, but I will give him a shot :)

This is the animation I'm using, it has shifted the view to the right.

EnterByRight.xml

 <set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
    <translate android:fromXDelta="100%" android:toXDelta="0%"
      android:fromYDelta="0%" android:toYDelta="0%"
     android:duration="400"/>
   </set>

In my case, I am a TableLayout animation defined in xml. When I want it to slide in:

Animation animationEnterByRight = AnimationUtils.loadAnimation(this, R.anim.animationentrancebyright);
tableLayout.startAnimation(animationEnterByRight);

and this is due to the screen, I don’t need to place it outside first, the animation will take care of it for me. This works great if you want to revitalize your view immediately after downloading it.

"" , , , View.Visible View.Gone. , ?

!

+4

( ) , , . , View.GONE , .

, ( ), View.VISIBLE . , m .

+3

. , , - GONE, , addChild().

, addChild() .

, init , , 0,4 , 0,5 . , , , !

+2

outtoRight.setFillBefore(false);?

+1

PreDrawListner(), , .

yourview.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
    @Override
        public boolean onPreDraw() {
            yourview.getViewTreeObserver().removeOnPreDrawListener(this);
            yourview.setTranslationX(something that will take it out of the screen, depends on padding);
            yourview.runIntroAnimation();
            return false;
       }
};
+1

All Articles