【发布时间】:2017-06-21 06:27:03
【问题描述】:
我正在开发一个 Android 应用,它几乎在每个活动上都有相同的背景图像和底部导航栏。
我想重用这段代码,而不是每次都写出来:
这是我的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background_image">
<android.support.design.widget.BottomNavigationView
android:layout_gravity="bottom"
android:id="@+id/bottom_nav_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@drawable/bottom_nav_menu_image"
xmlns:android="http://schemas.android.com/apk/res/android" />
</LinearLayout>
这将是所有视图的基本背景;但是,我将为每个布局在其顶部放置不同的布局。是否可以使用插入和合并标签以这种方式开始每个新活动?
【问题讨论】:
-
制作上述代码的 xml 并使用
并在应用程序 xml 的每个布局中使用这一行 -
我在主 xml 布局中该行之后放置的所有内容都会被考虑在模板 xml 文件中的 LinearLayout 中吗?
-
@ScottWeller 您可以将包含布局放在任何父布局中,例如线性布局、相对布局等。是的,您可以在
-
@ScottWeller- 是的。这将在您的主要线性布局中考虑。
标签: android android-layout android-xml