SetAnimation vs startAnimation in android

I basically want to move the view from one place to another, plus I also want to gradually increase its height. So I have to use setAnimation or startAnimation.

TranslateAnimation ta = new TranslateAnimation(0, 0, Animation.RELATIVE_TO_SELF, -otherview.getHeight());
ta.setDuration(1000);
ta.setFillAfter(true);

myview.startAnimation(ta); //or, which one to use and what is the difference. 

myview.setAnimation(ta);

question: how to move this relative layout?

I tried myview.scrollTo(x,y)but did not use. Is it possible to gradually increase the viewing height?

+5
source share
2 answers

Use startAnimation.

Below is an example snippet

trans = new TranslateAnimation(0, 100, 0, 100);
trans.setDuration(250);
trans.setInterpolator(new AccelerateInterpolator(1.0f));
someView.startAnimation(trans);

plus I also want to gradually increase its height,

To do this, you will scale the animation.

If you want to combine them into one file, use Set.

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
   <scale android:fromXScale="0.0" android:fromYScale="0.0"
          android:toXScale="1.0" android:toYScale="1.0" 
          android:duration="700" android:fillBefore="false" />
   <translate android:fromXDelta="-200" android:fromYDelta="-200"
          android:duration="700" />
</set>

Put below code inside java file:

Animation logoMoveAnimation = AnimationUtils.loadAnimation(this, R.anim.logoanimation); 
logoIV.startAnimation(logoMoveAnimation);

setAnimation

. .

startAnimation

, , startAnimation. , ,

1) ,

2) , .

+18

.

SetAnimation

viewGroup, . ,

StartAnimation

, .

+1

All Articles