gpt4 book ai didi

android - 如何将 BottomNavigationView 与 NavigationView 一起对齐到 Activity 的底部?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:05:13 25 4
gpt4 key购买 nike

我正在尝试在同一 Activity 中实现 BottomNavigationViewNavigationView,但 BottomNavigationView 似乎没有位于底部。

因为 BottomNavigationView 位于 Activity 的中心。我浏览了有关此问题的互联网,但没有找到任何解决方案。

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)

最佳答案

试试这个:

<?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>

关于android - 如何将 BottomNavigationView 与 NavigationView 一起对齐到 Activity 的底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42930808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com