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

  • Home
  • SEARCH
  • 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 8265899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:57:52+00:00 2026-06-08T04:57:52+00:00

I want to put a layout into another one via layoutInflater. Here’s the main_layout.xml

  • 0

I want to put a layout into another one via layoutInflater.

Here’s the main_layout.xml file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ImageView
    android:id="@+id/ads_image_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/ic_launcher" />

<RelativeLayout
    android:id="@+id/host_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/navigation_buttons_layout"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/ads_image_view" >
</RelativeLayout>

<RelativeLayout
    android:id="@+id/navigation_buttons_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true" >


    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Button" />

</RelativeLayout>

and here’s the vitrin_layout.xml file:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff0000"
    android:text="smallred" />

and finally the onCreate method for my main activity:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);
    ViewGroup parent = (ViewGroup) findViewById(R.id.host_layout);
    View view = LayoutInflater.from(getBaseContext()).inflate(
            R.layout.vitrin_layout, null);
    parent.addView(view, LayoutParams.FILL_PARENT);

    setTitle(getString(R.string.title_activity_vitrin));
}

The problem is that the vitrin_layout, does not fit into its parent(host_layout); although I’ve set fill_parent where ever I could!

I can’t figure out why.

Edited: I’m really sorry, but i’d pasted wrong vitrin_layout file, I fixed it.

  • 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-08T04:57:54+00:00Added an answer on June 8, 2026 at 4:57 am

    Use this addView method. By the way don’t use getBaseContext() unless you know why you are using it, instead use context of an activity (this).

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);
        ViewGroup parent = (ViewGroup) findViewById(R.id.host_layout);
        View view = LayoutInflater.from(this).inflate(R.layout.vitrin_layout, null);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT); 
        parent.addView(view, params);
    
        setTitle(getString(R.string.title_activity_vitrin));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to put the apk file into the Kindle Fire storage(through USB cable)
I have 4-5 grid panels, one form panel and want to put it into
i have some controllers, i want to put categories names into layout, like menu,
I developed a Sitecore control I'd like to put into a layout on one
I want to put two side by side on another (I have three )
I want to put all my resources into a ClientBundle for easy management. So
I want to put a web into webview.These is a video in the web.The
I try to put a branching diagram into lists and sublists layout is msg01
I want to place the RSS Viewer web part into a page layout I've
i want to put some string of a bundle into an custom dialog. So

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.