2017-03-21 61 views
2

我試圖對BottomNavigationViewNavigationView一起執行相同的活動,但BottomNavigationView似乎並不在底部。如何將BottomNavigationView與NavigationView的活動底部對齊?

由於BottomNavigationView位於活動的中心。我通過互聯網瀏覽了這個問題,但沒有找到任何解決方案。

enter image description here

我的XML代碼:顯示

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/main_content"> 

    <include layout="@layout/search_toolbar"/> 


</RelativeLayout> 

<android.support.design.widget.NavigationView 
    android:id="@+id/main_drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:menu="@menu/navigation_menu" 
    android:layout_gravity="start" 
    app:itemTextColor="#e6000000" 
    app:itemIconTint="#8c000000" 
    app:headerLayout="@layout/navigation_header"> 
</android.support.design.widget.NavigationView> 

<android.support.design.widget.BottomNavigationView 
    android:id="@+id/bottom_navigation_bar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    android:itemBackground="@color/colorPrimary" 
    app:menu="@menu/bottom_navigation" /> 

錯誤: onMeasureError

java.lang.IllegalStateException: Child android.support.design.widget.BottomNavigationView{64f98f6c V.E...... ......I. 0,0-0,0 #7f0c0080 app:id/bottom_navigation_bar} at index 2 does not have a valid layout_gravity - must be Gravity.LEFT, Gravity.RIGHT or Gravity.NO_GRAVITY 
at android.support.v4.widget.DrawerLayout.onMeasure_Original(DrawerLayout.java:1112) 
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java) 
at android.view.View.measure(View.java:19734) 
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 
at android.view.View.measure(View.java:19734) 
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715) 
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) 
at android.view.View.measure(View.java:19734) 
at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:589) 
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:342) 
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429) 
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:368) 
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:567) 
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:549) 
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:863) 
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:549) 
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$1(RenderTask.java:680) 
at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
at java.lang.Thread.run(Thread.java:745) 

回答

3

試試這個:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 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"> 

    <RelativeLayout 
     android:id="@+id/main_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <include layout="@layout/search_toolbar" /> 


     <android.support.design.widget.BottomNavigationView 
      android:id="@+id/bottom_navigation_bar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:itemBackground="@color/colorPrimary" 
      app:menu="@menu/bottom_navigation" /> 
    </RelativeLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/main_drawer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:headerLayout="@layout/navigation_header" 
     app:itemIconTint="#8c000000" 
     app:itemTextColor="#e6000000" 
     app:menu="@menu/navigation_menu" /> 

</android.support.v4.widget.DrawerLayout> 
+0

非常感謝。這解決了我的問題。再次感謝。 –