Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
691 views
in Technique[技术] by (71.8m points)

animation - setAnimation vs startAnimation in android

I basically want to move a view from 1 location to another, plus I also want to increase its height gradually, So what should I 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 no use. Is it possible to gradually increase the view height gradually?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use startAnimation.

Below is sample 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 increase its height gradually,

For this you will Scale animation.

If you want to combine them into single 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>

Place the below code inside the java file:

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

setAnimation

Sets the next animation to play for this view.But view animation does not start yet.

startAnimation

If you want the animation to play immediately, use startAnimation. This method provides allows fine-grained control over the start time and invalidation, but you must make sure that

1) the animation has a start time set,

2) the view will be invalidated when the animation is supposed to start.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...