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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:32:13+00:00 2026-06-18T08:32:13+00:00

edit: Added a bounty. Hopefully this will draw some attention to the issue at

  • 0

edit: Added a bounty. Hopefully this will draw some attention to the issue at hand.

I am currently trying to solve a problem in which an animation is continuously run on the main screen of an application animating a baby sleeping. this is done by having an imageView and replacing the current image in the animation with the next in line. Seing as there are more than 500 images this becomes very CPU intensive as each time an image is replaced the entire View Hierachy is re-calculated. Is there any way to NOT recalculate the entire view hierachy during this animation?

The run method looks like this :

        @Override
    public void run() {
        if (bitmap != null) {
            bitmap.recycle();
        }
        final String name = String.format(Locale.ENGLISH, pattern, current);
        final int id = getResources().getIdentifier(name, "drawable", getPackageName());
        if (id != 0) {
            bitmap = BitmapFactory.decodeResource(getResources(), id);
            view.setImageBitmap(bitmap);
        }
        current++;
        if (runAgain()) {
            frameCounter++;
            long nextAt = firstFrameAt + (frameCounter * interval);
            long delay = nextAt - SystemClock.elapsedRealtime() - 1;
            if (delay > 0) {
                handler.postDelayed(this, delay);
            } else {
                this.run();
            }
        }
    }

edit: I’ve been thinking about creating my own custom ImageView and overriding whatever method causes the problem. Would this be a viable solution?

  • 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-18T08:32:14+00:00Added an answer on June 18, 2026 at 8:32 am

    I solved the problem by implementing my own custom ImageView overriding the following two methods:

    @Override
    public void setImageBitmap(final Bitmap bitmap) {
        if (VERSION.SDK_INT < VERSION_CODES.ICE_CREAM_SANDWICH) {
    
            // The currently set Drawable
            Bitmap oldBitmap = null;
            try
            {
                oldBitmap = ((BitmapDrawable)this.getDrawable()).getBitmap();   
            }catch(NullPointerException e)
            {
                Log.d("setImageBitmap", "oldBitmap is null");
            }
    
            if (null != oldBitmap && oldBitmap != bitmap) {
                final int oldWidth = oldBitmap.getWidth();
                final int oldHeight = oldBitmap.getHeight();
    
                /**
                 * Ignore the next requestLayout call if the new Bitmap is the
                 * same size as the currently displayed one.
                 * */
                mIgnoreNextRequestLayout = oldHeight == bitmap.getHeight()
                        && oldWidth == bitmap.getWidth();
            }
        }
    
        super.setImageBitmap(bitmap);
    }
    
    @Override
    public void requestLayout() {
        if (!mIgnoreNextRequestLayout) {
            super.requestLayout();
            Log.d("RequestLayout", "Requesting new layout");
        }
        else
            Log.d("RequestLayout", "Ignoring next requestLayout");
    
        // Reset Flag so that the requestLayout() will work again
        mIgnoreNextRequestLayout = false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

edit added a test with regexpr to solve the problem techfoobar pointed out edit
EDIT I added this note to explain why I keep this question here. I
Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
EDIT : Accepted answer points out what my issue was. I added another answer
This is pretty straight forward. EDIT: Updated question and added fourth echo. Here is
EDIT: Rewrote the question. Added bounty as its important for me. The final hint
I've now added a bounty which will be awarded to anyone who can take
EDIT: I will leave this here as an example. Read the comments for more
Edit: Added bounty because I'm seeking an MVC3 solution (if one exists) other than
EDIT: I added a bounty, if someone could help me figure out what I

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.