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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:31:25+00:00 2026-06-17T12:31:25+00:00

I have an imageview with a default image. Now when I try to click

  • 0

I have an imageview with a default image. Now when I try to click it, I want it to animate that displays 4 frames of images. How could I accomplish this, I tried a simpler approach (more of a dumb approach) by changing the imageresource 4 times, as expected the image changes so fast that the animating image effect is not visible. Any ideas?

I tried this approach:

Gem = (ImageView)v;
    Gem.setImageResource(com.example.gems.R.drawable.bd1);
    Gem.postDelayed(new Runnable() {
        public void run() {
            Gem.setImageResource(com.example.gems.R.drawable.bd2);
            Gem.postDelayed(new Runnable() {
                public void run() {
                    Gem.setImageResource(com.example.gems.R.drawable.bd3);
                    Gem.postDelayed(new Runnable() {
                        public void run() {
                            Gem.setImageResource(com.example.gems.R.drawable.bd4);
                            Gem.postDelayed(new Runnable() {
                                public void run() {
                                }
                            }, 500);
                        }
                    }, 500);
                }
            }, 500);
        }
    }, 500);

It worked, but is there a better way to this without coding too much lines? I have 25 kinds of images and each image has 4 frames.

EDIT:

I tried using xml transition files:

Java file:

Resources res = this.getResources();
    Gem = (ImageView)v;
    TransitionDrawable transition;

    transition = (TransitionDrawable)
            res.getDrawable(R.drawable.blue_diamond_animation);
    Gem.setImageDrawable(transition);
    transition.startTransition(3000);

xml file:

 <transition xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/bd1"></item>
  <item android:drawable="@drawable/bd2"></item>
  <item android:drawable="@drawable/bd3"></item>
  <item android:drawable="@drawable/bd4"></item>
  <item android:drawable="@drawable/invi"></item>
 </transition>

This seems to work, but I don’t want to draw this images in a transition. I want to change the background in a transition. I tried changing this android:drawable to android:drawable but it doesn’t work.

  • 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-17T12:31:26+00:00Added an answer on June 17, 2026 at 12:31 pm

    It turns out that there is an exact class for this: AnimationDrawable

    Basically, just add frames with the other pictures to use in the animation to the AnimationDrawable object and specify how long they should display using addFrame(Drawable frame, int duration)

    Then set the ImageView to display whatever image it should start with and set the background to the AnimationDrawable you just made using setBackgroundDrawable(Animation)

    Lastly, start the animation in the onClick listener

    EDIT: FOR EXAMPLE

    AnimationDrawable ad = new AnimationDrawable();
    ad.addFrame(getResources().getDrawable(R.drawable.image1), 100);
    ad.addFrame(getResources().getDrawable(R.drawable.image2), 500);
    ad.addFrame(getResources().getDrawable(R.drawable.image3), 300);
    
    ImageView iv = (ImageView) findViewById(R.id.img);
    iv.setBackgroundDrawable(animation);
    

    And then in your onClick listener, just call ad.start

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

Sidebar

Related Questions

I have a ImageView and draw some things on that view. Now I want
I have an Image that is 1500x2048 I want this to display at its
I have an ImageView that has a drawable image resource set to a selector.
I have successfully placed an image into the lefthand ImageView of a default UITableViewCell
I have a default image set as a src for an ImageView. Then i
I have a UIButton that has a default image, and another image for highlight/selected
In my view i have ImageView.If i click ,it should open nextview. Please help
I have an ImageView in my activity that shows an active symbol when a
I have an ImageView and TextView . I want to place the TextView below
I have an ImageView with a source image set in the xml using the

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.