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'slayout_heightto"fill_parent", theCheckBoxtakes up the whole screen and is aligned center (i.e. - theTextViewdisappears).Scenario 2) If I instead set the
TextView'slayout_heightto"fill_parent", theCheckBoxdoes 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