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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:26:35+00:00 2026-05-19T06:26:35+00:00

i am trying to get the height of a view and it keeps returning

  • 0

i am trying to get the height of a view and it keeps returning 0.

this is what i have tried:

View hourView = View.inflate(mContext, R.layout.calendar_hour_item,null);
hourViewHeight = hourView.findViewById(R.id.mainLayout).getHeight();

i also tried hourViewHeight = hourView.getHeight(); as well but no joy.

i call those two lines inside a initialize() method located here:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calendar_day_screen);

        Intent intent = getIntent();

        mDate = new DateTime(intent.getStringExtra("date"));
        circleIcon = (ImageView) findViewById(R.id.circle);

        mHoursLayout = (RelativeLayout) findViewById(R.id.dayLayout);

        TopBarUtil topBar = new TopBarUtil(getApplicationContext());

        circleIcon.setOnClickListener(topBar.onActionClickListener());

        mContext = getApplicationContext();



        initialize();
    }

here is my xml layout:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:id="@+id/mainLayout" android:background="@layout/border">

    <TextView android:text="12am" android:id="@+id/hourTextView"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</RelativeLayout>

i basicllay want to get the height of the above xml layout but it always returns 0.

edit: i have also tried doing this below:

@Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();

         final View hourView = View.inflate(mContext, R.layout.calendar_hour_item,null);
        ViewTreeObserver observer = hourView.getViewTreeObserver();

        observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                hourView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                hourViewHeight = hourView.getHeight();
                Log.d(TAG, "hourViewHeight = " + hourViewHeight);
            }
        });

//      hourViewHeight = hourView.findViewById(R.id.mainLayout).getHeight();
//      Log.d(TAG, "hourViewHeight = " + hourViewHeight);
    }
  • 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-19T06:26:36+00:00Added an answer on May 19, 2026 at 6:26 am

    In the first example it didn’t worked because when you are querying them, the view still haven’t performed the layout and measure steps. You only told the view how it would “behave” in the layout, but it still didn’t calculated where to put each view.

    (Similar question: How to get the width and height of an android.widget.ImageView?)

    In the second example you posted, I don’t think you added the view to the activity so the activity won’t draw it hence, you will never read that log message. call setContentView or addView to some layout.

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

Sidebar

Related Questions

I'm trying to get the height of a html window's content. This is the
I'm trying to get a row in my table view to resize its height,
View Here: http://174.132.101.73/~ree/header/ I have a drop down box. I am trying to get
When my view is trying to load, the applications crashes and i get this
I am trying to set Padding Top to Specified View from another Layout Height
I'm trying to get an element to animate to its natural height - i.e.
I'm trying to use the jQuery .attr() property to get the height of an
I'm trying to animate a height property, when hovering, but I can't get it
Trying to get my css / C# functions to look like this: body {
I have done this previously but in a different way. I am trying to

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.