Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8899271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:49:04+00:00 2026-06-15T00:49:04+00:00

I have read several articles but none have fixed my problem using an animation

  • 0

I have read several articles but none have fixed my problem using an animation list. I already know I cant start the animation in onCreate() so I placed it inside an onClick() but it still does not work…

public class Main extends Activity implements OnClickListener {
/** Called when the activity is first created. */

AnimationDrawable explosionAnimation;
Button btnGo;
ImageView explosionImage;

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  explosionImage = (ImageView) findViewById(R.id.balloon);
  explosionImage.setBackgroundResource(R.drawable.explosion);
  explosionAnimation = (AnimationDrawable) explosionImage.getBackground();

  btnGo = (Button)findViewById(R.id.btnGo);
  btnGo.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId())
    {
    case R.id.btnGo:
        explosionAnimation.start();
        break;
    }
}
} 

explosion.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:oneshot="true">

<item android:drawable="@drawable/explode_1" android:duration="200" />
<item android:drawable="@drawable/explode_2" android:duration="200" />
<item android:drawable="@drawable/explode_3" android:duration="200" />
<item android:drawable="@drawable/explode_4" android:duration="200" />
<item android:drawable="@drawable/explode_5" android:duration="200" />

</animation-list>

main.xml

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

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

<ImageView
    android:id="@+id/balloon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="30dp"
    android:src="@drawable/balloon" />

<Button 
    android:id = "@+id/btnGo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="10dp"
    android:text="Play"
    />

</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:49:05+00:00Added an answer on June 15, 2026 at 12:49 am

    On your main.xml
    change the image view src to android:src="@drawable/explosion"

    then on your Main.java

    change

    explosionAnimation=(AnimationDrawable)((ImageView) explosionImage).getDrawable();

    try it. it should work

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read through several articles which are alternatives to using setpixel/getpixel but I
I have read several articles on when to use nested classes, but none that
I've read several articles about push button events in Qt but none seem to
I have read several articles and tutorials on the MVVM pattern but there is
I feel bad about not getting this. But, although I have read several articles
I have read several articles and questions on concept of foreign key vs independent
I have read several forums but can't find the solution to this. int sIndex
I have read several post on both matters but I haven't seen anyone comparing
I have read several questions regarding this but I fear they may be out
I have read several posts about the configuration manager in VS2010 (or before) but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.