Панель инструментов не отображается полностью - PullRequest
0 голосов
/ 18 января 2020

Я использую от ToolBar, как показано ниже, в моем проекте, и когда я удаляю app:layout_constraintTop_toTopOf="parent" из Toolbar, это хорошо работает, но RecyclerView накладывается на Toolbar, и когда я добавил его, ToolBar показывал половину :

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbarCourses"
        style="@style/CustomToolbar"
        android:background="@color/biscay"
        app:layout_constraintBottom_toTopOf="@+id/swpCourses"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_scrollFlags="scroll|enterAlways">

    </androidx.appcompat.widget.Toolbar>

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swpCourses"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbarCourses">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rcvCourses"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </androidx.recyclerview.widget.RecyclerView>
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

А вот style из ToolBar:

<style name="CustomToolbar">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">?android:attr/actionBarSize</item>
</style>

Но покажите мне toolBar, как показано ниже, и не показывайте полностью toolbar: enter image description here

1 Ответ

1 голос
/ 18 января 2020

Для SwipeRefreshLayout установлено:

    android:layout_width="0dp"
    android:layout_height="0dp"

Ограничения важнее, поэтому ширина и высота макета должны быть 0dp.

Полный код:

<androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbarCourses"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:background="@color/colorAccent"
        app:layout_constraintBottom_toTopOf="@+id/swpCourses"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_scrollFlags="scroll|enterAlways">

</androidx.appcompat.widget.Toolbar>

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swpCourses"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbarCourses">

    <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rcvCourses"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    </androidx.recyclerview.widget.RecyclerView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

...