0

我有LinearLayout保存在一個單獨的文件,並使用Include。 問題是我想要這個佈局在屏幕的底部。在我使用RelativeLayout的第一個佈局中很好。但在第二個佈局我使用LinearLayout,它似乎android:layout_alignParentBottom="true"不起作用。我怎樣才能解決這個問題 ?
這裏是我的代碼:
包括佈局:
`保持佈局在父佈局的底部

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@id/lytButtons" 
        style="@style/Register.LayoutButtons" 
        android:layout_alignParentBottom="true" 
        android:layout_marginBottom="8dp"> 
     . 
     . 
     . 
     . 
    </LinearLayout>` 

在第一個佈局,我有RelativeLayout的,並在第二個我有LinearLayout中。我如何更改包含在RelativeLayout和LinearLayout底部的包含的部分?

+0

'似乎android:layout_alignParentBottom =「true」does not work'。不,不是的**。它只適用於** RelativeLayout **父項。 – 2015-03-25 11:51:35

+3

對於'LinearLayout',使用'android:layout_gravity =「bottom」' – Piyush 2015-03-25 11:52:04

+0

正確和我的問題在這裏。我如何修復linearLayout? – 2015-03-25 11:53:31

回答

1

每當你要包括這個佈局在父佈局,只需指定它應該去:

<include 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    layout="@layout/yourLayout" /> 

編輯以下皮什·古普塔註釋:如果父佈局將是一個LinearLayout中,只需更換alignParentBottom:

<include 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    layout="@layout/yourLayout" /> 
+0

OP要包含在'LinearLayout'中。適用於'RelativeLayout'。 – Piyush 2015-03-25 11:58:45

+0

嘗試它,但沒有工作:/讓我工作在其中更多。我會用你的想法,如果我解決它,我會接受你的回答:) – 2015-03-25 12:05:36

1

解決你的困惑我給你的示例代碼添加腳註

頁腳佈局:footer_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.test.MainActivity" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Footer Layout" /> 

</LinearLayout> 

只是簡單的textview顯示爲頁腳。

主要佈局:activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 

    <include 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     layout="@layout/footer_layout" /> 

</LinearLayout> 

輸出: enter image description here

讓我還是知道的任何查詢。