• [Android]Android布局优化之<include />


    转载请标明:转载于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>
  • 相关阅读:
    python 监听文件夹下的文件,将文本内容写入kafka,支持断电续传 (docker 发布)
    python监控目录和文件变化
    Python 单例
    Python 面向对象 继承
    Python 面向对象 多态
    Python 面向对象 类属性和类方法
    Python 基础2
    Python 面向对象
    【bird-front】全自动数据表格组件bird-grid
    【bird-java】bird-java系列文章汇总
  • 原文地址:https://www.cnblogs.com/Liuyt-61/p/6602891.html
Copyright © 2020-2023  润新知