【发布时间】:2023-04-04 16:31:01
【问题描述】:
我想重复使用顶部和底部屏幕 - 只使用上图中的红色部分。 中间白色部分,每种情况,我都需要写XML。
但我的应用始终具有相同的上下视图。我想写一次,然后重复使用。
有可能吗?如何在android上解决这个问题?
【问题讨论】:
我想重复使用顶部和底部屏幕 - 只使用上图中的红色部分。 中间白色部分,每种情况,我都需要写XML。
但我的应用始终具有相同的上下视图。我想写一次,然后重复使用。
有可能吗?如何在android上解决这个问题?
【问题讨论】:
您必须添加两个xml布局名称底部和顶部,然后您可以在任何您想要的布局中使用它,只需添加此代码
<include layout="@layout/top" />
<include layout="@layout/bottom" />
此解决方案对于工具栏布局很有用。
在底部和顶部布局中,编写您想要重复使用的代码。
例子:
<?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="match_parent">
<include layout="@layout/top" />
<ImageView
android:id="@+id/your_dynamic_part"
android:layout_width="wrap_content"
android:layout_height="300dp" />
<include layout="@layout/bottom" />
</LinearLayout>
【讨论】: