我知道這肯定是一個簡單的問題......我只是不知道如何解決它。如何讓視圖填充可用的空間?
左右(只是一個例子),
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<Button android:id="@+id/fakeButton"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
<Button android:id="@+id/saveSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/saveSearch"/>
</LinearLayout>
這是行不通的 - 第一個按鈕將使第二無形。重量會讓所有的比例都不是我想要的。
我是厚厚的嗎?
編輯:我不知道它,但它似乎是順序是重要的(從答案)。加載佈局是迭代的而不是整體的。您可以將第一個元素設置爲固定高度,剩下的元素將填充剩下的元素。但我需要的是讓最終的元素達到一個固定的高度。
我不明白這是如何工作的(儘管不要誤解我的意思 - 它/是/正在工作)。你能否給出更詳細的解釋? – Graeme
啊 - 如果LinearLayout中的一個孩子有一個layout_weight,那麼它的寬度(水平方向)或高度(垂直方向)將被忽略。相反,它會將其容器填充到體重爲0的其他兒童或體重> 0的其他兒童的程度,他們將通過比較體重值來分享容器的百分比。 – Graeme
你實際上需要考慮這個系統2次:首先,忽略重量,通常做佈局。如果LinearLayout中有額外的空間,並且有些孩子的體重> 0,那麼給體重> 0的兒童提供額外空間的一部分(水平和/或垂直),與體重總和成比例。 – Gregory