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>