工具栏将覆盖Recyclerview

时间:2020-10-13 16:52:12

标签: android kotlin android-recyclerview android-toolbar

XML代码:-

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

<androidx.constraintlayout.widget.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <include
        android:id="@+id/toolbar1"
        layout="@layout/toolbar_standalone" />


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />
    </androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

请帮助更正代码。因此工具栏不会覆盖 回收者视图。我已经尝试过此更改,但无法正常工作 完美。

app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"

1 个答案:

答案 0 :(得分:0)

您可以宽度和高度进行布局

您可以设置默认的操作栏大小

android:layout_height="?attr/actionBarSize"

并使用layout_constraintTop_toBottomOf

  <androidx.constraintlayout.widget.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <include
        android:id="@+id/toolbar1"
        layout="@layout/toolbar_standalone"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"/>


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar1" />
</androidx.constraintlayout.widget.ConstraintLayout>