0
我使用兩個帶有片段的佈局,一個用於portait模式,另一個用於橫向。我需要爲這兩個佈局添加一個粘性頁腳,並且我已經成功將其添加到肖像佈局,但是當我使用類似的代碼進行佈局時,它不起作用。如果設置了所述片段的layout_width
到0dp
,我看到既不片段,如果我設置layout_width
到wrap_content
或fill_parent
,片段彼此重疊。添加頁腳到兩個片段的佈局
這是我到目前爲止有:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<!-- Footer -->
<TextView
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<!-- Footer -->
<fragment android:name="com.app.listing1"
android:id="@+id/fragment1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_above="@id/footer"
/>
<fragment android:name="com.app.listing2"
android:id="@+id/fragment2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_above="@id/footer"
/>
</RelativeLayout>
編輯
我已經變得有點接近我想要的東西。如果我在fragment1上放置一個寬度,那麼我就會得到我正在尋找的東西,但顯然,這並不理想。出於某種原因,在兩個片段的佈局,以及每個片段內的佈局設置layout_width =「WRAP_CONTENT」,結果在所述第一片段接管整個屏幕:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<!-- Footer -->
<TextView
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<!-- Footer -->
<fragment android:name="com.app.listing1"
android:id="@+id/fragment1"
android:layout_width="200dp"
android:layout_height="fill_parent"
android:layout_above="@id/footer"
android:layout_toLeftOf="@id/fragment2"
/>
<fragment android:name="com.app.listing2"
android:id="@+id/fragment2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_above="@id/footer"
android:layout_toRightOf="@id/fragment1"
/>
</RelativeLayout>
嗯,沒有工作。我添加機器人:layout_alignParentLeft =「真」的第一片段和機器人:layout_alignParentRight =「真」,以第二,但他們仍然重疊 – 2012-04-07 20:22:37
對不起,我的意思left_of/right_of。如果你想佈置你fragment2到片段1的右側添加'機器人:layout_toRightOf =「@ ID /片段1」'你fragment2和你的片段1設置爲'機器人:layout_width =「WRAP_CONTENT」' – 207 2012-04-07 20:28:55
哎,仍然沒有工作。現在它只在整個屏幕上顯示片段1。你知道片段中的內容是否會影響它?我將RelativeLayouts的layout_width和layout_height設置爲每個片段內的fill_parent。在處理Android佈局時,我有這樣的心理障礙。 – 2012-04-08 00:21:39