我敢肯定,我失去了一些東西簡單...安卓:簡單的LinearLayout和FILL_PARENT問題
背景:
我是新來的Android和UI設計,我只是想玩弄與佈局。現在我想在文本標籤上疊加一個複選框。我使用下面的XML佈局,工作正常:
<?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>
我的測試(只是爲了獲得對事物如何工作的感覺):
方案1)當我設置
CheckBox
的layout_height
至"fill_parent"
,CheckBox
佔據整個屏幕並對齊中心(即 -TextView
消失)。方案2)如果我代替設置
TextView
的layout_height
到"fill_parent"
的CheckBox
確實不消失。實際上,沒有任何東西會消失,並且佈局看起來與上面的xml一樣,其中所有內容都被推到左上角。
問題(和註釋):
怎麼來的情景1的工作它的工作方式?
這種行爲似乎與我不一致。我認爲fill_parent
只能讓元素填充父級中可用的任何空間。所以對我來說,似乎TextView
應該得到它需要的任何空間需要(因爲它是wrap_content
),但CheckBox
應該佔用剩餘的空間(所以TextView
將被強制到屏幕的底部,但不可見)。換句話說......場景2對我來說很有意義,但場景1沒有。
請解釋:-)。
感謝,
湯姆
你可能想讀這個(如果不是已經):如何android繪製視圖?鏈接:http://developer.android.com/guide/topics/ui/how-android-draws.html – Samuh 2009-12-24 15:15:32