Android优化——UI优化(二)

使用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"设置复用的布局文件

时间: 2024-08-08 01:27:29

Android优化——UI优化(二)的相关文章

Android优化——UI优化(三)

使用ViewStub延迟加载 1.ViewStub延迟加载 ViewStub是一个不可见的,大小为0的View,最佳用途就是实现View的延迟加载,在需要的时候再加载View,可Java中常见的性能优化方法延迟加载一样. 当调用ViewStub的setVisibility函数设置为可见或则调用inflate初始化该View的时候,ViewStub引用的资源开始初始 化,然后引用的资源替代ViewStub自己的位置填充在ViewStub的位置.因此在没有调用setVisibility(int)或则

Android优化——UI优化(一)优化布局层次

优化布局层次 1.避免布局镶嵌过深(如下) <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&quo

Android优化——UI优化(一)

优化布局层次 1.避免布局镶嵌过深(如下) <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&quo

Android优化——UI优化(四)

使用style替换背景,防止Activity黑色背景闪过 1.原来的布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/img_

Android优化——UI优化(四) 使用stytle

使用style替换背景,防止Activity黑色背景闪过 1.原来的布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/img_

[Unity优化]UI优化(二):Mask组件分析

参考链接: https://www.sohu.com/a/211665096_99940808 1.Mask组件实现原理 使用模板测试,一方面使Mask对象所在区域的模板缓冲值置为1,另一方面使被Mask的对象进行模板测试,如果是1才进行渲染 2.Mask增加drawcall 3.Mask增加overdraw 如下,左边没加Mask,右边加Mask,颜色越深overdraw越大 原文地址:https://www.cnblogs.com/lyh916/p/10587632.html

android产品研发(二十一)--&gt;UI优化

转载请标明出处:一片枫叶的专栏 上一篇文章中我们讲解了android产品研发过程中的代码Review.通过代码Review能够提高产品质量,增强团队成员之间的沟通,提高开发效率,所以良好的产品开发迭代过程中,代码Review是一个必不可少的步骤.那么如何进行代码Review呢?我们主要讲解了团队成员之间的代码Review,代码lint检查,开发规范等方面的知识点,更多关于代码Review相关的知识可参考我的:android产品研发(二十)–>代码Review 本文我们将讲解一下android U

Android开发性能优化总结(二)

接上一篇<Android开发性能优化总结(一)> 一.安卓UI性能检测与优化 UI是安卓应用程序与用户打交道的最直接途径,UI设计的好不好,直接影响到用户的体验,如果没有达到他们心目中的自然流畅细节,用户要是能够感觉出来,少则影响心情,多则卸载应用:所以一个应用的UI显示性能问题就不得不被开发人员重视. 1.UI卡顿常见原因: 在UI线程中做了耗时操作,导致UI线程卡顿: 布局Layout过于复杂,无法在16ms内完成渲染: 同一时间动画执行的次数过多,导致CPU或GPU负载过重: View过

Android性能优化方法(二)

在Android应用里,最耗费内存的就是图片资源.而且在Android系统中,读取位图Bitmap时,分给虚拟机中的图片的堆栈大小只有8M,如果超出了,就会出现OutOfMemory异常.所以,对于图片的内存优化,是Android应用开发中比较重要的内容. 1) 要及时回收Bitmap的内存 Bitmap类有一个方法recycle(),从方法名可以看出意思是回收.这里就有疑问了,Android系统有自己的垃圾回收机制,可以不定期的回收掉不使用的内存空间,当然也包括Bitmap的空间.那为什么还需