簡體   English   中英

Android UI:將一個片段對齊到另一個底部對齊的片段之上

[英]Android UI: align a fragment above another fragment that is aligned bottom

我已經一年多沒有為Android開發了,我對它有點生疏了。 我正在嘗試設置一個有點簡單的UI :屏幕底部的底部欄和其上方的片段(但沒有填充整個高度)。 像這樣的東西:

在此處輸入圖片說明

我認為這會很簡單,但經過一段時間的努力,我無法在沒有一些“黑客”的情況下使其工作。

底部欄也實現為Fragment 這是我的 XML:

<RelativeLayout 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:orientation="vertical" >

    <fragment
        android:id="@+id/bottomBar"
        android:name="com.mytestpackage.BottomBarFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

    <FrameLayout
        android:id="@+id/fragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/bottomBar"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

Fragment中的Fragment是從代碼動態加載的。 使用上面的代碼粘貼,fragmentContainer 與底部對齊但它不在底部欄上方,它們是重疊的。 如果我從 fragmentContainer 中移除alignParentBottom ,那么它就會被放置在屏幕的頂部。

就像我說的,我找到了兩個“黑客”來解決它,但我不太喜歡它們:

1- 為 fragmentContainer 設置padding / margin底部。 2- 在屏幕頂部使用填充空布局並將 fragmentContainer 設置為低於該布局。

有沒有什么方法可以實現我想要的布局,而不必使用我說的那些技巧?

謝謝!

添加到相對布局:

android:gravity="bottom"

啊, android:orientation="vertical"RelativeLayout來說毫無意義

一個更簡單的解決方案是使用具有垂直方向和重力底部的LinearLayout而不是RelativeLayout

暫無
暫無

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

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