簡體   English   中英

使用兩個片段將頁腳添加到布局

[英]Add footer to layout with two fragments

我使用了兩種帶有片段的布局,一種用於縱向模式,一種用於橫向。 我需要為兩種布局添加一個粘性頁腳,我已經成功地將它添加到縱向布局,但是當我對橫向布局使用類似的代碼時,它不起作用。 如果我將片段的layout_width設置為0dp ,我看不到任何片段,如果我將layout_width設置為wrap_contentfill_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>

編輯:

片段相互重疊,因為您沒有在 RelativeLayout 中對齊它們。 如果您希望它們水平排列,請使用layout_toRightOflayout_toLeftOf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM