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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:50:07+00:00 2026-06-05T16:50:07+00:00

I have a Layout containing a fragment. I set width of Layout to let’s

  • 0

I have a Layout containing a fragment. I set width of Layout to let’s say 300dip.

I want to calculate the width of the children programmatically in relation to the 300dip of the parent.

I can’t do it in XML since it has some “tricks” and using weigths or RelativeLayout will not work and I have to use maths.

Here is the fragment with the containing layout…

<LinearLayout 
    android:layout_width="300dip"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >

    <fragment
        android:id="@+id/tabbar"
        android:name="com.test.MyFragment"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

In MyFragment there’s the method:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d("test", "container: "  + container);
    View view = inflater.inflate(R.layout.mylayout, container, false);
    Log.d("test", "view width: "  + view.getWidth());

    //do things with view

    return view;
}

I get the outputs container: null and view width: 0 and I can’t find any onMeasure method in the fragment or similar.

  • 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-05T16:50:08+00:00Added an answer on June 5, 2026 at 4:50 pm

    onCreateView is called before your layouts have been inflated, so they have no height or width. If you want to fiddle with how layouts and views are drawn, you can create your own view, extending View, and implement onLayout(); If you Google, there’s plenty of examples of that.

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

Sidebar

Related Questions

I have a tab layout containing 3 tabs. I want to add 4th tab
I have a panel with a form layout, containing several buttons. now I want
I have a fairly complex layout (containing RelativeLayouts, TextViews and ImageViews) that I want
I have a layout with a set of divs each containing three fields in
I have a layout as follows: <div style=width: 300> <div style=width: 300>Some Content</div> </div
I have a layout that contains two ImageViews. I want one of them to
I have an Activity with a layout containing a custom ImageView and a few
I have two Android projects, a 'library project' containing a custom layout, and an
I have a layout containing two textViews and one ImageView. the first text is
Sorry for basic question. I have the following layout: #existing-files .image-row{ width: 700px; border:

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.