转载请标明:转载于http://www.cnblogs.com/Liuyt-61/p/6602891.html
-------------------------------------------------------------------------------------------
>将可复用的组件抽取出来并通过include标签使用。
作用: 将共同的组件抽取出来单独放到一个xml文件中,然后使用include标签导入公用布局。
效果:提高UI的制作和复用效率,也能保证制作的UI布局更加规整和易维护。
eg:<include layout="@layout/common_title"/>
common_title.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#000000" android:paddingBottom="10dp" android:paddingTop="10dp" > <TextView android:id="@+id/re" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:text="返回" android:textColor="#ffffff" android:textSize="14sp" /> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="布局优化" android:textColor="#ffffff" android:textSize="18sp" /> <TextView android:id="@+id/fun" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="10dp" android:text="功能" android:textColor="#ffffff" android:textSize="14sp" /> </RelativeLayout> -------------------------------------- main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <include layout="@layout/common_title" /> </LinearLayout>
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步