当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>