2010-09-30 31 views
2

你好。這是我的佈局Android fill_parent問題

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ListView android:id="@+id/lv" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@android:color/white" /> 
    <Button android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/lv" /> 
</RelativeLayout> 

當我運行這個列表視圖佔據全屏。我想要的是列表視圖是除了按鈕區域之外的全屏而不提及dp。由於

回答

1

嘗試一些可能性後,我發現這是有幫助的

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ListView android:id="@+id/lv" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@android:color/white" android:layout_above="@+id/bt"/> 
    <Button android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/bt" android:layout_alignParentBottom="true"/> 
</RelativeLayout> 

感謝大家的答案。

0

我想你可以這樣做:

寫:

<Button android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/lv" /> 

前:

<ListView android:id="@+id/lv" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/white" /> 

這樣的:

<Button android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/lv" /> 

<ListView android:id="@+id/lv" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/white" /> 

,但我不知道

+0

你不能做到這一點。您必須先聲明listview才能引用它。相反,將按鈕設置爲alignparentbottom,然後設置它上面的列表視圖 – Falmarri 2010-09-30 15:56:32

1

@mnish是非常正確的,除了在Android 1.5中,您必須在使用它們之前聲明id。

<ListView android:id="@+id/lv" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/white" /> 
<Button android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/lv" /> 

您可以使用layout_above,layout_below,layout_toLeftOf,...

+0

這是真的。但是,因爲我提到fill_parent作爲高度,該按鈕不可見。 – Prabhat 2010-09-30 12:47:10

+0

通過將android:layout_alignParentTop =「true」放在你的列表視圖 – fedj 2010-09-30 13:24:03

1

我認爲LinearLayout更適合這裏。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    > 
    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     /> 
    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     /> 
</LinearLayout> 

(是的,wrap_contentListViewlayout_height正確,layout_weight="1"將確保它擴展儘可能)