zoukankan      html  css  js  c++  java
  • [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>
  • 相关阅读:
    echarts 折线图(移动端)X轴显示不全
    文字超出省略号类型
    逻辑运算为true
    13年省赛总结
    PyCharm专业版破解教程
    django之定义统一返回数据格式与GET/POST装饰器
    Xmind8破解教程
    django之mysqlclient安装
    django之“static”全局设置
    django之集成第三方支付平台PaysAPI与百度云视频点播服务接入
  • 原文地址:https://www.cnblogs.com/Liuyt-61/p/6602891.html
Copyright © 2011-2022 走看看