views:

41

answers:

3

Using a layoutanimation on one of my views.

android:layoutAnimation="@anim/animate_layout"

The animation is done each time one enters that view. It will however not run if that view was already active and the user changed to another application and then returned to it. In order to do that, I need to overwrite the onresume() method and call it from there.

How can I call the layoutAnimation from within the code in order to run it again for the whole layout?

A: 

Look into LayoutAnimationController and start()

Pentium10
Tried it by both using the constructor and even setanimation before calling its start method. It still didnt work. Should there have been more steps than adding the animation object and calling it's start method?
Milan
+1  A: 

Another option, besides what Pentium10 suggested, would be trying to do this:

Animation animation = AnimationUtils.loadAnimation(ctx, android.R.anim.fade_out);
target.startAnimation(animation);    

Where ctx could be something like YourActivity.this, and target is the View you want to animate.

Cristian
That worked directly. Thanks
Milan
A: 

Hi, I'm also trying to get my animation to start over when the user gets to se the layout again. I get force close with this code implemented.

public void onResume(){
     super.onResume();
     View layout = findViewById(R.layout.main);
     Animation animation = AnimationUtils.loadAnimation(CrookTranslate.this, R.anim.fade_from_left);
     layout.startAnimation(animation);        
    }   

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/from_left"
android:id="@+id/fade_from_left"
android:delay="3.0"
/> 

enter code here

Martin