首页 > 解决方案 > 如何制作工具栏,使其始终位于其下的所有视图和布局之上?

问题描述

我目前在活动中有一个工具栏和一个 FrameLayout。问题是在运行时,FrameLayout 扩展并覆盖了我不想要的工具栏。我应该如何修改工具栏以使其位于其下所有视图的顶部?

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:mapbox="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"
        mapbox:layout_constraintBottom_toTopOf="@id/frameLayout"
        mapbox:layout_constraintLeft_toLeftOf="parent"
        mapbox:layout_constraintRight_toRightOf="parent"
        mapbox:layout_constraintTop_toTopOf="parent" />

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="600dp"
        mapbox:layout_constraintBottom_toBottomOf="parent"
        mapbox:layout_constraintEnd_toEndOf="parent"
        mapbox:layout_constraintStart_toStartOf="parent"
        mapbox:layout_constraintTop_toBottomOf="@id/toolbar"
        android:paddingTop="2dp">

        // Map here.

    </FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

标签: androidandroid-layoutandroid-toolbar

解决方案


推荐阅读