android:include包含布局
一,代码:
公用部分
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/bar"
android:gravity="center"
android:background="@android:color/holo_blue_light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标题栏"
android:textSize="30dp"
android:textColor="@android:color/white"
/>
</LinearLayout>
包含:
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.Scroll2Activity">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:id="@+id/houseNestedScrollView"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/title_bar"/>
二,测试效果

浙公网安备 33010602011771号