Liuyt_61

愿踏遍山河,仍觉人间值得

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

转载请标明:转载于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>

 

posted on 2017-03-22 23:44  Liuyt_61  阅读(1101)  评论(0编辑  收藏  举报