当include布局的父布局为相对布局,要使用相对位置时,需要加上宽高属性,id的名称也要和include的这个布局的根布局id名称一样,不然会出现各种奇怪问题,下面是一个使用例子

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include
            android:id="@+id/topbar"
            layout="@layout/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/topbar"></FrameLayout>

    </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:skin="http://schemas.android.com/android/skin"
    android:id="@+id/topbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/common_68dp"
    android:fitsSystemWindows="true"
    android:paddingTop="@dimen/common_20dp"
    android:theme="@style/AppTheme.AppBarOverlay"
    app:elevation="0dp"
    skin:enable="true">

</com.google.android.material.appbar.AppBarLayout>

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐