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

The Archive Base Latest Questions

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

I have a layout that I am using as a parent layout template. Depending

  • 0

I have a layout that I am using as a parent layout template. Depending on what Activity I launch, I would like to populate the contents of a LinearLayout in the parent template with an inflated view. Now, if I place the parent and child layouts into the same XML file, things look good. But if I use setContentView() on the parent layout, and then inflate the child view and add it to the same place in the parent layout, things don’t work. Both the LinearLayout that I am putting the child view into, and the LinearLayout that is the root of the child view have android:layout_height="fill_parent", but the child view is unable to fill the LinearLayout that it is added to.

Is there something obvious I’m not doing correctly? Remember, these layouts should look identical, just one method is static, and the other is dynamic. I assume that this has something to do with the parent layout dimensions being calculated and not updated after the child view is inflated.

Thanks!

  • 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-26T05:13:17+00:00Added an answer on May 26, 2026 at 5:13 am

    OK, I figured this out.

    You need to pass the child’s parent view into the inflater when you are inflating the child so that the inflater knows how big to make it. I was inflating with a null parent and then adding the child to the parent, but that resulted in the child behaving as if I set the layout params to “wrap_content”.

    Incorrect:

    ViewGroup parent = (ViewGroup) root.findViewById(R.id.parent);
    parent.removeAllViews();
    LinearLayout child;
    child = (LinearLayout) inflater.inflate(R.layout.child, null);
    parent.addView(child);
    

    Correct:

    ViewGroup parent = (ViewGroup) root.findViewById(R.id.parent);
    parent.removeAllViews();
    (LinearLayout) inflater.inflate(R.layout.child, parent);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have panel that is using group layout to organize some label. I want
I have a basic website nav layout that looks like this: <li class=folder parent_folder>
I have a large png that I would like to use as a background
I have a Layout (using TableLayout, etc...) which works well. It seems like this:
I have a class that extends Activity and inflates another xml layout in the
I'm using a Relative layout as the root or parent container and I have
I have a layout that is working, but it has one very annoying problem..
I have this layout that works correctly, a relative layout with a text view
Simple - I have a layout that is 800 by 600. When I press
Hy, I have a layout in the views/layout that has 2 cols and then

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.