sai sai - 11 days ago 6
Android Question

how to start Animation in onCreate() in android?

I have done like these it not working?

public class AnimationActivity extends Activity{
private AnimationDrawable yourAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.animation);
getIntentValues();
final ImageView imageView = (ImageView) findViewById(R.id.animation_iv);
imageView.setBackgroundResource(R.drawable.loadinganim);
yourAnimation = (AnimationDrawable) imageView.getBackground();
yourAnimation.start();
}


res\drawable\loading.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/v1" android:duration="160" />
<item android:drawable="@drawable/v4" android:duration="160" />
<item android:drawable="@drawable/v7" android:duration="160" />
<item android:drawable="@drawable/v8" android:duration="160" />
<item android:drawable="@drawable/v9" android:duration="160" />
<item android:drawable="@drawable/v10" android:duration="160" />
<item android:drawable="@drawable/v11" android:duration="160" />
</animation-list>


res\layout\animation.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/animation_iv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>




Animation is starting on imageView onClick().if any one have idea help me.

Answer
          view.setImageResource(R.anim.framer);
          view.post(new Runnable() {
            public void run() {             
                AnimationDrawable animationDrawable = (AnimationDrawable)view.getDrawable();
                animationDrawable.start();
            }
          });

This worked for me try it !!!!

Comments