1
這裏是我的佈局XML:ViewFlipper寬度包裹內容和FILL_PARENT不工作
<?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">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="true">
<TableRow
android:background="#FF0000">
<ViewFlipper
android:id="@+id/viewer_something"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CCCCCC">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button one" />
</LinearLayout>
<LinearLayout
android:id="@+id/view2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button two" />
</LinearLayout>
</ViewFlipper>
</TableRow>
<TableRow
android:background="#FF0000">
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button three" />
</TableRow>
</TableLayout>
</LinearLayout>
因此,在短期,我有一個ViewFlipper通過tablerow內。即使所有元素都指定了fill_parent,ViewFlipper也會縮小到其內容的大小。在下面的屏幕截圖中,ViewFlipper具有灰色背景,TableRows具有紅色背景。
是的,確實如此。我不明白它爲什麼有效,但它工作。你可以解釋嗎? – 2011-06-05 23:34:19
假設你有一個包含各種子視圖的父視圖。如果您將每個子視圖設置爲wrap_content,然後指定佈局權重,則每個視圖將展開填充其重量與總重量的比例的剩餘空白區域。因此,如果在父視圖(LinearLayout)內只有一個視圖(ViewFlipper),則設置佈局權重將使其填充剩餘的空白區域。這就是佈局重量的原因。至於爲什麼fill_parent的寬度不起作用,我不太確定,但這可能是測量尚未繪製視圖的問題。 – 2011-06-05 23:39:32
謝謝。仍然困惑爲什麼fill_parent沒有在第一個地方工作 - 就像你說的 - 但我現在明白爲什麼添加layout_weight添加額外的保險,它會填補所有內容。 – 2011-06-06 00:10:33