Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 513
Programmer Avatar asked Jun 06 '12 07:06

Programmer


People also ask

What are two different types of view animations?

There are two types of animations that you can do with the view animation framework: Tween animation: Creates an animation by performing a series of transformations on a single image with an Animation. Frame animation: or creates an animation by showing a sequence of images in order with an AnimationDrawable .

What is pivotX and pivotY in Android?

The pivotX and pivotY is the central point of the animation. So for example if you want to do Zoom In animation you can use this <? xml version="1.0" encoding="utf-8"?> <

What is twined animation in Android?

Tween animations are a specific type of animation related to rotation, sliding, and movement of an object. This article explains some common Tween animations. Now we move to the code part of this article.

What is fillAfter in Android?

android:fillAfter When set to true, the animation transformation is applied after the animation is over. The default value is false. If fillEnabled is not set to true and the animation is not set on a View, fillAfter is assumed to be true.


2 Answers

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.

like image 159
Vipul Avatar answered Sep 29 '22 21:09

Vipul


This is my understanding.

SetAnimation

when the view is added to the viewGroup,animation will be called.when the view has been added,the animation will not be called

StartAnimation

animation will be called all the time even though the view has been added.

like image 24
user2024270 Avatar answered Sep 29 '22 20:09

user2024270