1
私は CoordinatorLayoutBottomNavigation下を示したい私のアプリケーションで

に、私はコードの下に書くこのためBottomNavigation CoordinatorLayoutを表示する方法:アンドロイド

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true" 
    > 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/main.appbar" 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/main.collapsing" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 


      <include 
       android:id="@+id/mainToolbar" 
       layout="@layout/toolbar_main" /> 

     </android.support.design.widget.CollapsingToolbarLayout> 

    </android.support.design.widget.AppBarLayout> 


    <com.aurelhubert.ahbottomnavigation.AHBottomNavigationViewPager 
     android:id="@+id/mainViewPager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/mainBottomNavigation" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

    <com.aurelhubert.ahbottomnavigation.AHBottomNavigation 
     android:id="@+id/mainBottomNavigation" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     app:layout_anchorGravity="bottom" 
     app:selectedBackgroundVisible="true" /> 

</android.support.design.widget.CoordinatorLayout> 

しかし、実行時にアプリケーションが私にCoordinatorLayoutBottomNavigationトップを見ます!

BottomNavigationのボトムをCoordinatorLayoutと表示するにはどうすればよいですか?

+0

あなたの 'bottomnavigation'には' match_parent'という属性があります。アンドロイド:layout_height = "match_parent" '代わりに' wrap_content'を使います。 – Ibrahim

+0

@IbrahimAli、レイアウトの下部にこのAHBottomNavigationを表示したい –

答えて

5

私は答えが遅すぎることを望みません。私はちょうど同じ問題を抱えていた、私はアンドロイドを使った:layout_gravity = "bottom"。 私は、BottomNavigationViewというツールバーを持っていて、中にはフラグメントのプレースホルダーとして使用されるFrameLayoutがあります。ここに私のXMLのレイアウトは次のとおりです。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bg_main" 
    android:minHeight="?attr/actionBarSize"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/colorTab" 
    app:layout_scrollFlags="scroll|enterAlways" 
    /> 
</android.support.design.widget.AppBarLayout> 

<FrameLayout 
    android:id="@+id/fragment_placeholder" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    > 

    <android.support.v4.view.ViewPager 
     android:id="@+id/slide_viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</FrameLayout> 

<android.support.design.widget.BottomNavigationView 
    android:id="@+id/bottom_navigation" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    app:itemBackground="@color/colorTab" 
    app:itemIconTint="@drawable/bottom_navigation_toolbar" 
    app:itemTextColor="@drawable/bottom_navigation_toolbar" 
    app:menu="@menu/bottom_bar" 
    /> 

</android.support.design.widget.CoordinatorLayout> 

またthis質問をチェックアウト、それはほとんど同じレイアウトを使用し、それはまた、あなたがスクロールするとき、それは隠しようBottomNavigationViewの動作を変更する方法を示しています。あなたがその機能を実装したい場合は、クラスBottomNavigationBehaviorを作成することを確認してください(またはあなたがそれを呼び出すために好きな)とXMLであなたのBottomNavigationViewに次の行を追加します

app:layout_behavior="com.yourpackage.yourpackage.BottomNavigationBehavior" 

はそれが役に立てば幸い!