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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:26:12+00:00 2026-05-23T05:26:12+00:00

Accessing myView.getWidth() and getHeight() always return zero, and I understand this is because I’m

  • 0

Accessing myView.getWidth() and getHeight() always return zero, and I understand this is because I’m calling them too early, before the views have been laid out.

But how CAN I access the size of views from an activity? I can’t see a method to override and the docs aren’t suggesting a lifecycle event I can catch.

===================================

Thanks Tanner. Here’s the code I used, which works fine.

LinearLayout root = (LinearLayout)findViewById(R.id.main);
Display d = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int screenWidth = d.getWidth();
int screenHeight = d.getHeight();
root.measure(screenWidth, screenHeight);
View myView = findViewById(R.id.myView);
int width = myView.getMeasuredWidth();
  • 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-05-23T05:26:13+00:00Added an answer on May 23, 2026 at 5:26 am

    Have a look at this: http://developer.android.com/guide/topics/ui/how-android-draws.html

    Have you tried calling measure() and then getMeasuredWidth() on your view?

    Notice there is also the method requestLayout()

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

Sidebar

Related Questions

While accessing a webservice which is availbale at http://recpushdata.cyndigo.com/jobs.asmx , I am getting this
When accessing my site from a number of machines $_SERVER['REMOTE_ADDR'] always resolves to an
Accessing a member on Form may cause a runtime exception because it is a
I'm going to try and explain this without showing any code because I don't
Is accessing a bool field atomic in C#? In particular, do I need to
When accessing an object in a DataTable retrieved from a database, are there any
When accessing values from an SqlDataReader is there a performance difference between these two:
When accessing the winapi method CloseHandle() via .net P/Invoke, should the argument be IntPtr
Can accessing (for read only) memory freed cause an access violation, and, if so,
When accessing member that doesn't exist, automatically creates the object. $obj = new ClassName();

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.