Android LinearLayout 和 RecyclerView BottomNavigation 对齐

标签 android kotlin

所以我不知道如何在 RecyclerView 下的 LinearLayout 中对齐我的底部导航。这些项目是 RecyclerView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".CategoryActivity">

   <android.support.design.widget.AppBarLayout
           android:theme="@style/AppTheme.AppBarOverlay"
           android:layout_width="match_parent"
           android:layout_height="wrap_content">

       <android.support.v7.widget.Toolbar
               android:id="@+id/toolbar"
               android:background="?attr/colorPrimary"
               app:popupTheme="@style/AppTheme.PopupOverlay"
               android:layout_width="match_parent"
               android:layout_height="?attr/actionBarSize">
       </android.support.v7.widget.Toolbar>


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

    <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_category"
            android:layout_margin="8dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    </android.support.v7.widget.RecyclerView>

    <android.support.design.widget.BottomNavigationView
            android:id="@+id/nav_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?android:attr/windowBackground"
            android:layout_alignParentBottom="true"
            app:menu="@menu/bottom_nav_menu"/>

</LinearLayout>

enter image description here

导航应该始终在底部。

最佳答案

好的,这是你的布局,它应该按你的预期工作

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />


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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_category"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/nav_view"
        android:layout_below="@+id/appbar"
        android:layout_margin="8dp"
        android:orientation="vertical" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/menu_navigation" />

</RelativeLayout>

关于Android LinearLayout 和 RecyclerView BottomNavigation 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56330451/

相关文章:

android - 在带有 Parceler 的 Android 中使用 CLEAN 架构

kotlin - JavaFX - 如何在 Kotlin 中使用 MapValueFactory?

kotlin - 如何在 Kotlin 中启动 String 数组?

android - Netinfo.isConnected 在 Android 中总是返回 true

android - 如何在Android中按@键打开对话框窗口?

android - 如何在 Kotlin 中将 HashMap 转换为 JSON

android - Kotlin如何获取和打开视频

android - 在 Android 中为 ArrayList 设置自定义适配器

android - 我可以在伴生对象中共享 ViewModel 吗?

android - 如何找到我在 Android Studio 中打开的项目的 API 级别?