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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:59:55+00:00 2026-05-20T19:59:55+00:00

In an Activity , I am manually inflating a View object from XML as

  • 0

In an Activity, I am manually inflating a View object from XML as follows:

    LayoutInflater inflater = LayoutInflater.from (this);
    View topView = inflater.inflate (R.layout.topview_layout, null);

I won’t be adding the view to any display hierarchy, but rather using it to generate bitmaps which I will then display. Since those bitmaps will be the size of my (main) screen, I try to cause the layout to occur:

    Display display = ((WindowManager) getSystemService (Context.WINDOW_SERVICE))
                        .getDefaultDisplay();
    topView.measure (display.getWidth (), display.getHeight ());
    topView.layout (0, 0, display.getWidth (), display.getHeight ());

(It is getting the proper size of the display in the above code.)

topView is a LinearLayout which contains a few other views. One of them is an ImageView:

    ImageView childView = (ImageView) pageView.findViewById (R.id.textArea);

However, this view never seems to be informed about its dimensions after the call to layout():

    int childViewWidth = childView.getWidth ();
    int childViewHeight = childView.getHeight ();

(The dimensions retrieved by the above code are 0,0.)

All of the above code occurs linearly, and is called from within my Activity subclass’ onCreate() method.

The layout XML I’m testing with is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/topView"
        android:orientation="vertical"
        android:background="@color/blue"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <ImageView
        android:id="@+id/textArea"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/gold"/>
</LinearLayout>

I would most appreciate any clues!

NOTE: Edited to add the layout XML and the measure() call pointed out as missing by Romain Guy.

  • 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-20T19:59:55+00:00Added an answer on May 20, 2026 at 7:59 pm

    You need to call measure() before you call layout().

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

Sidebar

Related Questions

I tried running this Query in CRM 2011: var activity = (from a in
This activity is used for login. It post the username and password to a
My Activity creates an AsyncTask that loads data from a file and updates the
I understand an activity needs to be defined/described in the AndroidManifest xml file. I
This is the scenario: I have one image background set on an activity. On
I've written an application that creates a map activity. From there the user can
In my activity, on user's request for preferences screen, I call: startActivity(new Intent(this, Preferences.class));
What I wanted to achieve is this: Right after the activity starts, I want
I have a list activity, and I chose to manually add the first item
I navigate from Activity1 to Activity2 On Activity 2 I have a keyboard and

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.