ConstraintLayout RecyclerView显示在BottomNavigationView下

Mou*_*ssa 2 android android-recyclerview android-constraintlayout

如何使用ConstraintLayout在BottomNavigationView下不显示RecyclerView。

这是结果(回收站应该显示20个元素)

在此处输入图片说明

这是XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/myListSimple"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation"/>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

Paw*_*ski 5

您正在使用match_parent两个android:layout_widthandroid:layout_heightRecyclerView不推荐用于Views包含在ConstraintLayout。您应该改用0dp匹配约束:

<android.support.v7.widget.RecyclerView
    android:id="@+id/myListSimple"
    android:scrollbars="vertical"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toTopOf="@id/navigation"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
Run Code Online (Sandbox Code Playgroud)