如何使用另一个外部xml视图android



我有一个视图xml文件abc.xml,它是一个Linearlayout

我还有另一个xml文件def.xml,我想在其中使用abc.xml。我想知道如何在我的def.xml文件中写入此内容?

我的def.xml文件看起来像:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

</LinearLayout>
</layout>

就是这样:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/abc"/>
</LinearLayout>
</layout>

最新更新