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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:30:13+00:00 2026-06-16T00:30:13+00:00

This question has been asked several times in various forms but I haven’t found

  • 0

This question has been asked several times in various forms but I haven’t found a definitive answer.

I need to be able to get dimensions and positions of descendant Views after the initial layout of a container (a contentView). The dimensions required in this case are of a View(Group) that is not predictable – might have multiple lines of text, minimum height to accommodate decoration, etc. I don’t want to do it every on every layout pass (onLayout). The measurement I need is a from a deeply nested child, so overriding the onLayout/onMeasure of each container in between seems a poor choice. I’m not going to do anything that’ll cause a loop (trigger-event-during-event).

Romain Guy hinted once that we could just .post a Runnable in the constructor of a View (which AFAIK would be in the UI thread). This seems to work on most devices (on 3 of the 4 I have personally), but fails on Nexus S. Looks like Nexus S doesn’t have dimensions for everything until it’s done one pass per child, and does not have the correct dimensions when the posted Runnable‘s run method is invoked. I tried counting layout passes (in onLayout) and comparing to getChildCount, which again works on 3 out of 4, but a different 3 (fails on Droid Razr, which seems to do just one pass – and get all measurements – regardless of the number of children). I tried various permutations of the above (posting normally; posting to a Handler; casting getContext() to an Activity and calling runOnUiThread… same results for all).

I ended up using a horrible shameful no-good hack, by checking the height of the target group against its parent’s height – if it’s different, it means it’s been laid out. Obviously, not the best approach – but the only one that seems to work reliably between various devices and implementations. I know there’s no built-in event or callback we can use, but is there a better way?

TYIA

/EDIT The bottom line for me I guess is that the Nexus S does not wait until after layout has completed when .posting() a Runnable, as is the case on all other devices I’ve tested, and as suggested by Romain Guy and others. I have not found a good workaround. Is there one?

  • 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-16T00:30:14+00:00Added an answer on June 16, 2026 at 12:30 am

    I’ve been successful using the OnGlobalLayoutListener.

    It worked great on my Nexus S

    final LinearLayout marker = (LinearLayout) findViewById(R.id.distance_marker);
    OnGlobalLayoutListener listener = new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            //some code using marker.getHeight(), etc.
            markersContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    };
    marker.getViewTreeObserver().addOnGlobalLayoutListener(listener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question has been asked several times here, but I can't find answer for
I know this question has been asked many times before, but I haven't found
Maybe this question has been asked many times before, but I never found a
Though this question has been asked several times but I really couldn't find any
Ok, so I know this question has been asked in different forms several times,
This question has been asked several times, but I researched and still can't solve
This question has been asked several times already, but has been solved with poor
I know this question has been asked several times, but I can't quite seem
I know this question has been asked several times on SO, but none of
I realize this question has been asked several times in several different forms ,

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.