zoukankan      html  css  js  c++  java
  • Android优化——UI优化(二) 使用include标签复用布局

    使用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"/>
    • 1

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

  • 相关阅读:
    php设计模式 — 简单工厂模式(静态工厂方法模式)
    Vue-Router
    各种选项卡
    jq动画
    如何使用swiper写轮播
    Gulp代码压缩
    闭包
    jquery.validation校验
    grunt-js文件压缩
    CSS
  • 原文地址:https://www.cnblogs.com/ldq2016/p/5226576.html
Copyright © 2011-2022 走看看