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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:13:07+00:00 2026-06-13T22:13:07+00:00

First off, I’ve been reading this site for years now and it’s helped me

  • 0

First off, I’ve been reading this site for years now and it’s helped me out of a bind several times, so thank you to the community here who contribute, and hopefully you can help me with a problem of my own.

I’m just starting out with Android development at my company and I’m attempting to port an existing application from Windows Mobile C# to Android Java. Most of it is going smoothly, but one area I’m having some difficulty is the UI.

The Windows Mobile application reads in a survey specification from a file when the WinForm is created. In the case of a closed-ended question (such as multiple choice), I need to populate the screen with either a CheckBox or RadioButton control for each applicable answer in the spec. Creating the layout and controls required is no problem, but we also have a requirement that the screen does not scroll. Because of this our software needs to be able to calculate the best possible fit within the available screen space without overflow (ie. 1-4 columns used for display) before it’s displayed

I have written my UI (at least the layout) as both an XML resource or Java code, but because methods like GetWidth() and GetHeight() return 0 in onCreate(), I haven’t yet been able to add this required pre-processing.

All of this needs to happen prior to the screen showing. If anyone can point me in the right direction, I would be immensely grateful.

  • 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-13T22:13:08+00:00Added an answer on June 13, 2026 at 10:13 pm

    When Android builds the UI from a layout, the root of the layout requests all of it’s children to report their desired size by calling onMeasure(). It does this is a recursive fashion bottom up. if necessary, the parent view will then set the size of the children so that they fit. As you have found, this measuring pass is not finished during onCreate().

    Try a global layout listener.

    public void onCreate(Bundle savedInstanceState)
    {
         super.onCreate(savedInstanceState);
    
         // inflate your main layout here (use RelativeLayout or whatever your root ViewGroup type is
         LinearLayout mainLayout = (LinearLayout ) this.getLayoutInflater().inflate(R.layout.main, null); 
    
         // set a global layout listener which will be called when the layout pass is completed and the view is drawn
         mainLayout.getViewTreeObserver().addOnGlobalLayoutListener(
         new ViewTreeObserver.OnGlobalLayoutListener() {
              public void onGlobalLayout() {
                   // measure your views here
              }
         }
     );
    
     setContentView(mainLayout);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, thank you to everyone on this site...it's been INCREDIBLY helpful in getting
First off I apologize if there is another post out there that answers this,
First off, this question is ripped out from this question. I did it because
First off - apologies if this or a similar question has been asked before.
First off I use this code to make the navigation bar always stay fixed;
First off tags wont work. I say this because i create 4 buttons all
First off this is for homework or... project. I'm having trouble understanding the idea
First off, my problem is quite similar to this one . I would like
First off, I am cross-posting this from Server Fault because I did not receive
First off: Everything works , but I would like to fine tune this 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.