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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:03:46+00:00 2026-05-13T07:03:46+00:00

I’m sure I am missing something simple… Background: I am new to android and

  • 0

I’m sure I am missing something simple…

Background:

I am new to android and UI design, and I just wanted to play around with layouts. Right now I want to stack a checkbox on top of text label. I am using the following xml layout which works fine:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <CheckBox android:id="@+id/check_box"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/check_box_text" />

    <TextView android:id="@+id/dummy_display"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/dummy_label" />

</LinearLayout>

My Tests (just to get a feel for how things works):

  • Scenario 1) When I set the CheckBox‘s layout_height to "fill_parent", the CheckBox takes up the whole screen and is aligned center (i.e. – the TextView disappears).

  • Scenario 2) If I instead set the TextView‘s layout_height to "fill_parent", the CheckBox does NOT disappear. In fact, nothing disappears, and the layout looks the same as the above xml where everything is pushed to the top-left.

The Question (and comments):

How come Scenario 1 works the way it works?

This behavior seems inconsistent to me. I thought that fill_parent is only supposed to let the element fill up whatever space is available in the parent. So to me, it seems that the TextView should get whatever space it needs (since it is wrap_content), but the CheckBox should take up the rest of the space (so the TextView would be forced to the bottom of the screen, but not invisible). In other words… Scenario 2 makes sense to me, but scenario 1 does not.

Please explain :-).

Thanks,

Tom

  • 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-13T07:03:46+00:00Added an answer on May 13, 2026 at 7:03 am

    LinearLayout measures it children as a single step one by one, so in your first example
    it sees that first child want to have all available height it gives it to it.
    In your second example it gives all available place to the second child.
    If you want checkbox to take all the place except place needed for text box you should change
    layout_height of checkbox to wrap_parent and set layout_weight property of each child, layout weight indicates how much of available place after all children were measured should be add to the each of them. To be more specific the way it works by steps:
    1) Parent of LinearLayout tells linear layout how big it can be
    2) LinearLayout asks all it children in order they specified about their layout params and distributes available space.
    3) If any free space is still available it distributes it between children according to their weight’s ( layout weight is between 0 and 1 , 0 – by default)
    Hope it helps
    Edit:
    I’ve checked LinearLayout source code and found out what if a linear layout had a FILL_PARENT layout params and not zero weight measuring code will set layout height to WRAP_CONTENT and later distribute space between all children according to weights.

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

Sidebar

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.