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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:50:12+00:00 2026-06-18T23:50:12+00:00

I am trying to create a bitmap out of a relative layout that i

  • 0

I am trying to create a bitmap out of a relative layout that i have created programmatically.
The Realtivelayout is showing as expected but when i try to create a bitmap , it returns illegal argument exception that height and width must be > 0
this is how i am doing it

Bitmap.createBitmap(saveLayout.getWidth(),
            saveLayout.getHeight(), Bitmap.Config.ARGB_8888);

Any pointers?

Edit: added this code, too:

    ViewTreeObserver viewTreeObserver = saveLayout.getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver
                .addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        saveLayout.getViewTreeObserver()
                                .removeGlobalOnLayoutListener(this);
                        viewWidth = saveLayout.getWidth();
                        viewHeight = saveLayout.getHeight();

                    }
                });
    }

In above given code onGlobalLayout() also never seemed to be called.

  • 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-18T23:50:13+00:00Added an answer on June 18, 2026 at 11:50 pm

    If you’re programmatically creating the saveLayout, you may be asking for its width and height too early. (just an educated guess, because I can’t see the rest of your code)

    See this explanation

    The reason why that createBitmap() call throws that exception is:

    if the width or height are <= 0

    So, try to defer creating the Bitmap until after the view appears, or find another way to calculate the width/height.

    This question has a few options/answers for how to defer this calculation to avoid 0 results

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

Sidebar

Related Questions

I am trying to create a simple android app in Java but I have
I am trying to create an Oval Bitmap and I need to get a
I am trying to create a BUTTON over BITMAP or OVERLAYING buttons on the
Trying to create a black line in my view to separate text blocks but
Trying to create a new Dedicated Cache Role in Windows Azure but get the
I am trying to create a spinning wheel with text on it. I have
I'm trying to figure out a way to create a zero-width, zero-height image which
I'm trying to figure out why, when I create a movieclip in flashdevelop, said
i'm failing miserably trying to work out how to create a toolbar in css.
I'm trying to create a Win32 window that has rounded corners and is resizable

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.