Android优化——UI优化(二)

来源:互联网 发布:c语言学生综合测评系统 编辑:程序博客网 时间:2024/06/03 16:16

使用include标签复用布局


- 1.include标签的作用

假如说我下图的这个布局在很多界面都用到了,我该怎么办?每个页面都写一遍的话,代码太冗余,并且维护难度加大。
这里写图片描述

<LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity"    android:orientation="vertical">    <include layout="@layout/activity_clude_item"/>    <TextView        android:layout_width="match_parent"        android:layout_height="match_parent"        android:gravity="center"        android:text="这是中间的东西"/></LinearLayout>

这里写图片描述

上边的这个布局我就用的include标签,代码显然更加的整洁,并且增加的布局的复用性,降低了app的使用内存

- 2.include标签的用法

<include layout="@layout/activity_clude_item"/>

其中我们使用layout="@layout/activity_clude_item"设置复用的布局文件

0 0
原创粉丝点击