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

The Archive Base Latest Questions

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

I have an Activity with a view hierarchy as follows: <RelativeLayout> <LinearLayout> <GridLayout />

  • 0

I have an Activity with a view hierarchy as follows:

<RelativeLayout>
    <LinearLayout>
        <GridLayout />
    </LinearLayout>
</RelativeLayout>

The top RelativeLayout takes up the full screen while the LinearLayout takes up a subset of the screen. I’m trying to set the size of the children views of the GridLayout in such a way that with n rows and m columns the size of cells is directly related to the n,m values and the width and height of the LinearLayout.

So for example, I’m trying to get the cell width and height as follows:

int linearLayoutWidth = mLinearLayout.getMeasuredWidth();
int linearLayoutHeight = mLinearLayout.getMeasuredHeight();
...

int rows = mGridModel.getRows() + 1;
int columns = mGridModel.getColumns() + 1;
int cellWidth = (int) (linearLayoutWidth / columns);
int cellHeight = (int) (linearLayoutHeight / rows);

Unfortunately, mLinearLayout.getMeasuredWidth() does not return the correct size when the view is created. It always returns the actual device’s screen width until the views have been fully laid out – in which case it is too late. I have already given my children cell views the size based on the initially completely incorrect values.

My question is – how do I know when the views have been FULLY laid out. I need to query for their correct or actual measured width/height.

setContentView() creates the views and theoretically lays them out. But they views are not guaranteed to be in their final correct locations/sizes yet.

  • 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-02T01:34:20+00:00Added an answer on June 2, 2026 at 1:34 am

    You can add ViewObserver to any view, in this observer there is a callback method onGlobalLayout, invoked when Layout has been laid;

    ViewTreeObserver observer = view.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            //in here, place the code that requires you to know the dimensions.
    
    
             //this will be called as the layout is finished, prior to displaying.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity view that I have added in AppDelegate class to tap
I have an activity with a view pager and three pages to display. When
I have this code for my soundboard, public class soundboardActivity extends Activity { View
I have an activity with a custom view which extends EditText in it. Usually
Within one Activity I have th following piece of code: public void onStartMonitoringToggleClicked(View v)
I have implemented a custom view within another activity into a XML layout. The
can i use fragments and map view in the same activity. I have seen
I have a set of EditText widgets on my activity view, each on a
Is there a way to start an activity from a view? I have this
I am writing a android application where, on startup activity view, I have a

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.