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 9212655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:34:30+00:00 2026-06-18T01:34:30+00:00

I am trying to get frame by frame animation but its giving me a

  • 0

I am trying to get frame by frame animation but its giving me a force close and I am not sure as to why it is giving me a force close. It all seems alright to me.

Here is my code i hope some one can help?
Thanks in advance.

AnimationTest.java

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;

public class AnimationTest extends Activity {

AnimationDrawable animation;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    AnimationDrawable animation = new AnimationDrawable();
    animation.addFrame(getResources().getDrawable(R.drawable.up), 500);
    animation.addFrame(getResources().getDrawable(R.drawable.down), 500);

    animation.setOneShot(false);

    ImageView imageAnim =  (ImageView) findViewById(R.id.imageView1);
    imageAnim.setBackgroundDrawable(animation);

    // start the animation!
    animation.start();
} 

}

activity_main.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/imageView1"
        android:src="@drawable/down"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"/>
</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-18T01:34:31+00:00Added an answer on June 18, 2026 at 1:34 am

    You’re starting the animation in the onCreate Method , which will not work because your activity is not displaying yet, use a delayed runnable instead or a clickListener.

    you can test the animation using this code:

    // inside onCreate
       setContentView(R.layout.activity_main);
    
    
    final AnimationDrawable animation = new AnimationDrawable();
    animation.addFrame(getResources().getDrawable(R.drawable.up), 500);
    animation.addFrame(getResources().getDrawable(R.drawable.down), 500);
    
    animation.setOneShot(false);
    
    ImageView imageAnim =  (ImageView) findViewById(R.id.imageView1);
    imageAnim.setBackgroundDrawable(animation);
    Handler handler = new Handler();
    handler.postDelayed(new Runnable(){
    
    public void run(){
    
    animation.start();
    
    }
    }, 3000);
    

    Please make sure your ImageView has size, and no src is set to see what is going on, in your layout xml file do the following:

        android:layout_width="50dp"
        android:layout_height="50dp"
    

    and remove src attribute if any

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

Sidebar

Related Questions

I am still trying to figure out frame animation, but I need to use
I am trying to get a frame by frame animation to run on android
Hello I was trying to Pause Animation Drawable but could not succeeded. With the
Please help. Trying to get animation of frame position working inside a UITableViewCell, specifically
I am trying to get information about a movie (resolution, frame rate, bit rate,
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
I followed the instructions here to capture screenshots during animation (I am trying to
I have been trying to get it to work using this thread but can't
I am trying to get the new IOS 5 Container viewControllers working properly 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.