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

  • Home
  • SEARCH
  • 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 8756377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:04:24+00:00 2026-06-13T14:04:24+00:00

I created one simple demo project, which does the animation using AnimationDrawable class of

  • 0

I created one simple demo project, which does the animation using AnimationDrawable class of android.
Here is my java code:

public class TestAnimationActivity extends Activity {
    /** Called when the activity is first created. */

    ImageView imgCircleWhite,imgCircleYellow;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imgCircleYellow = (ImageView)findViewById(R.id.imgCircleYellow);

        animateState(true, imgCircleYellow);

    }

    public void animateState(boolean flag,ImageView imageView)
    {
        imgCircleYellow.setBackgroundResource(R.drawable.animate_circle_sensor_1);
        AnimationDrawable yourAnimation = (AnimationDrawable) imageView.getBackground(); 
        if(!flag)
        {   
            //imageView.getAnimation().reset();
            imageView.setBackgroundResource(R.drawable.circle_label_white_1);           
            yourAnimation.stop();           
        }
        else
        {
            imageView.setBackgroundResource(R.drawable.animate_circle_sensor_1); 
            yourAnimation = (AnimationDrawable) imageView.getBackground(); 
            yourAnimation.start();
        }
    }
}

Here is my main.xml file:

<?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/imgCircleYellow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/circle_label_yellow_1"/>

</LinearLayout>

Below is my animate_sensor_circle_1.xml, which I’ve put in drawable folder to use with:

<?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/circle_label_white_2"
        android:duration="50"/>
    <item
        android:drawable="@drawable/circle_label_yellow_1"
        android:duration="50"/>
</animation-list>

When I run the app, only the first item in the above xml file gets displayed, but animation does not occur repeatedly as it should done.
Can anyone direct me where I am going wrong?

  • 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-13T14:04:25+00:00Added an answer on June 13, 2026 at 2:04 pm

    It is not the right time to call the AnimationDrawable.start(). You should do this after the view initialization has been completed. Try this:

    final ImageView imgCircleYellow = (ImageView)findViewById(R.id.imgCircleYellow);
    imgCircleYellow.setBackgroundResource(R.drawable.animate_circle_sensor_1);
    imgCircleYellow.post(new Runnable() {
        @Override
        public void run() {
            animateState(true, imgCircleYellow);
        }
    

    Check this for more information: https://stackoverflow.com/a/5490922/813135

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

Sidebar

Related Questions

Using xlwDotNet, I have created a simple function which returns one number. Sometimes, something
I have created one android project with simple web view. I am trying to
I am new to Java programming, i created one class with name as Demo
I followed ChrisF here and write a simple demo . ...open your project in
I am a bit confused. I have created a simple form with a one
Can some one provide a link to create a simple server and client using
I'm trying to create a simple form with two different submit buttons: one which
I already have some simple project with one migration script: # --- !Ups create
Recently I have gone through with one simple threading program, which leads me some
I want to call web services in phonegap application. I am using demo code

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.