I am sure that I am missing something simple ...
Background:
I'm new to Android and UI design, and I just wanted to play around with layouts. Right now I want to check the box above the text label. I use the following xml layout that 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 understand how everything works):
Scenario 1) When I set the CheckBox layout_height to "fill_parent" , the CheckBox occupies the entire screen and is centered (that is, the TextView disappears).
Scenario 2) If instead of TextView layout_height "fill_parent" set CheckBox , then CheckBox will disappear NOT . Nothing actually disappears, and the layout looks the same as higher than xml, where everything fits in the top left.
Question (and comments):
Why does scenario 1 work the way it works?
This behavior seems inconsistent to me. I thought fill_parent should only allow the element to fill all the free space in the parent. Thus, it seems to me that the TextView should get any necessary space (since it is wrap_content ), but the CheckBox should occupy the rest of the space (so the TextView will 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
android user-interface xml layout
Tom
source share