2

我有3次主要活動垂直對齊3次:toolbarMainContainer & bottombar如何與不同高度

  • toolbar60dp
  • MainContainer是一個高度配對父親
  • bottombar50dp

與此問題,bottombar不顯示在所有,一旦MainContainer設置爲match-parent它填補佈局的休息和推bottombar出可見的區!同樣的事情,如果高度設置爲wrap-content!所以如何解決這個問題..!?

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="70dp" 
    android:background="@color/accent"/> 

    <FrameLayout 
    android:id="@+id/MainContainer" 
    android:layout_below="@id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/colorPrimary"/> 

    <com.roughike.bottombar.BottomBar 
    android:id="@+id/bottombar" 
    android:background="@color/black" 
    android:layout_below="@id/MainContainer" 
    android:layout_width="match_parent" 
    android:layout_height="50dp"/> 


</RelativeLayout> 

回答

3

您應該使用

android:layout_alignParentBottom="true" 

如果爲true,使得這一觀點的底部邊緣的 父底邊相匹配。容納底部邊緣。

嘗試

<com.roughike.bottombar.BottomBar 
    android:id="@+id/bottombar" 
    android:background="@color/black" 
    android:layout_below="@id/MainContainer" 
    android:layout_width="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_height="50dp"/> 

FYI

在你Framelayout部分添加android:layout_marginBottom="50dp"

+0

仍然沒有顯示.. –

+0

@SamZar的FrameLayout部分添加'機器人:layout_marginBottom = 「50dp」' –

+1

它的工作原理,謝謝:d,但是你應該加入這一行太'Android設備上編輯答案:layout_marginBottom =」 50dp「' –

1

mainContainer上的高度和寬度=匹配親和marign_bottom在mainContainer上50dp那底杆的

<RelativeLayout 
 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent"> 
 

 

 
    <android.support.v7.widget.Toolbar 
 
     android:id="@+id/toolbar" 
 
     android:layout_width="match_parent" 
 
     android:background="@color/accent" 
 
     android:layout_height="70dp"/> 
 

 
    <FrameLayout 
 
     android:id="@+id/MainContainer" 
 
     android:layout_below="@id/toolbar" 
 
     android:layout_width="match_parent" 
 
     android:background="@color/colorPrimary" 
 
     android:layout_height="match_parent" 
 
     android:layout_marginBottom="50dp"/> 
 

 
    <com.roughike.bottombar.BottomBar 
 
     android:layout_alignParentBottom="true" 
 
     android:id="@+id/bottombar" 
 
     android:layout_below="@id/MainContainer" 
 
     android:layout_width="match_parent" 
 
     android:background="@color/black" 
 
     android:layout_height="50dp"/> 
 

 

 
</RelativeLayout>

0

這是爲我工作高度

<?xml version="1.0" encoding="utf-8" ?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.truiton.bottomnavigation.MainActivity"> 
    <include 
    android:id="@+id/mainToolbar" 
    layout="@menu/toolbar" /> 

    <FrameLayout 
    android:id="@+id/mainFrameLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/mainToolbar" 
    android:layout_above="@+id/mainBottomNavigation" 
    /> 

    <android.support.design.widget.BottomNavigationView 
    android:id="@+id/mainBottomNavigation" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_gravity="start" 
    android:background="@color/bottom_navigation_view_background" 
    app:itemIconTint="@menu/nav_item_color_state" 
    app:itemTextColor="@menu/nav_item_color_state" 
    app:menu="@menu/bottom_navigation_main" 
    /> 

</RelativeLayout> 
+0

用戶使用'com.roughike.bottombar.BottomBar' –

+0

好吧,但對齊和佈局設置應該是相同的。 –

0

更好的解決方案是使用垂直方向的LinearLayout併爲其子設置權重。嘗試下面的代碼。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="70dp" 
    android:background="@color/accent"/> 

    <FrameLayout 
    android:id="@+id/MainContainer" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="@color/colorPrimary"/> 

    <com.roughike.bottombar.BottomBar 
    android:id="@+id/bottombar" 
    android:background="@color/black" 
    android:layout_width="match_parent" 
    android:layout_height="50dp"/> 

</LinearLayout>