android textview settext卡顿深层次原因
最近在公司项目里面发现listview里面的textview在调用settext函数的时候非常耗时,当时都有点不敢相信,这是因为如果你把textview设置成wrap_content,则每次调用settext之后会调用到
........40334034 if (mMovement != null) {4035 mMovement.initialize(this, (Spannable) text);40364037 /*4038 * Initializing the movement method will have set the4039 * selection, so reset mSelectionMoved to keep that from4040 * interfering with the normal on-focus selection-setting.4041 */4042 if (mEditor != null) mEditor.mSelectionMoved = false;4043 }4044 }40454046 if (mLayout != null) {
//这个函数非常重要4047 checkForRelayout();4048 }40494050 sendOnTextChanged(text, 0, oldlen, textLength);4051 onTextChanged(text, 0, oldlen, textLength);40524053 notifyViewAccessibilityStateChangedIfNeeded(AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT);4054
.........
checkForRelayout函数,这个函数根据文字的多少重新开始布局
6807 private void More ...checkForRelayout() {6808 // If we have a fixed width, we can just swap in a new text layout6809 // if the text height stays the same or if the view height is fixed.68106811 if ((mLayoutParams.width != LayoutParams.WRAP_CONTENT ||6812 (mMaxWidthMode == mMinWidthMode && mMaxWidth == mMinWidth)) &&6813 (mHint == null || mHintLayout != null) &&6814 (mRight - mLeft - getCompoundPaddingLeft() - getCompoundPaddingRight() > 0)) {6815 // Static width, so try making a new text layout.68166817 int oldht = mLayout.getHeight();6818 int want = mLayout.getWidth();6819 int hintWant = mHintLayout == null ? 0 : mHintLayout.getWidth();68206821 /*6822 * No need to bring the text into view, since the size is not6823 * changing (unless we do the requestLayout(), in which case it6824 * will happen at measure).6825 */6826 makeNewLayout(want, hintWant, UNKNOWN_BORING, UNKNOWN_BORING,6827 mRight - mLeft - getCompoundPaddingLeft() - getCompoundPaddingRight(),6828 false);68296830 if (mEllipsize != TextUtils.TruncateAt.MARQUEE) {6831 // In a fixed-height view, so use our new text layout.6832 if (mLayoutParams.height != LayoutParams.WRAP_CONTENT &&6833 mLayoutParams.height != LayoutParams.MATCH_PARENT) {6834 invalidate();6835 return;6836 }68376838 // Dynamic height, but height has stayed the same,6839 // so use our new text layout.6840 if (mLayout.getHeight() == oldht &&6841 (mHintLayout == null || mHintLayout.getHeight() == oldht)) {6842 invalidate();6843 return;6844 }6845 }68466847 // We lose: the height has changed and we have a dynamic height.6848 // Request a new view layout using our new text layout.6849 requestLayout();6850 invalidate();6851 } else {6852 // Dynamic width, so we have no choice but to request a new6853 // view layout with a new text layout.6854 nullLayouts();6855 requestLayout();6856 invalidate();6857 }6858 }
注释已经写的很明白了,所以宽度设定为一个数字或者match_parent能够使得settext所耗时间变短,就是这样。
android textview settext卡顿深层次原因的更多相关文章
- android TextView SetText卡顿原因
[android TextView SetText卡顿原因] 不要用wrap_content即可. 参考:http://blog.csdn.net/self_study/article/details ...
- Android TextView setText卡顿问题
TextView 是经常使用控件之中的一个,最经常使用的方法是setText() . 可是 我们在显示大量的文本的时候,使用setText还是会有一些性能的问题. 这篇文章 关于TextView的s ...
- android中fragment卡顿的原因
首页的ViewPager有十几个Fragment,在快速切换的时候,容易产生卡顿现象. 二.分析当ViewPager切换到当前的Fragment时,Fragment会加载布局并显示内容,如果用户这时快 ...
- android中listview滑动卡顿的原因
导致Android界面滑动卡顿主要有两个原因: 1.UI线程(main)有耗时操作 2.视图渲染时间过长,导致卡顿 http://www.tuicool.com/articles/fm2IFfU
- Android 界面滑动卡顿分析与解决方案(入门)
Android 界面滑动卡顿分析与解决方案(入门) 导致Android界面滑动卡顿主要有两个原因: 1.UI线程(main)有耗时操作 2.视图渲染时间过长,导致卡顿 目前只讲第1点,第二点相对比较复 ...
- Android性能优化----卡顿优化
前言 无论是启动,内存,布局等等这些优化,最终的目的就是为了应用不卡顿.应用的体验性好坏,最直观的表现就是应用的流畅程度,用户不知道什么启动优化,内存不足,等等,应用卡顿,那么这个应用就不行,被卸载的 ...
- Android中app卡顿原因分析示例
在知乎回答了一个“为什么微博的app在iPhone比Android上流畅”的问题.后面部分是一个典型的动画卡顿的性能分析过程,因此帖在这里.有编程问题可以在这里交流.知乎链接. =========== ...
- Android App解决卡顿慢之内存抖动及内存泄漏(发现和定位)
内存抖动是指在短时间内有大量的对象被创建或者被回收的现象,内存抖动出现原因主要是频繁(很重要)在循环里创建对象(导致大量对象在短时间内被创建,由于新对象是要占用内存空间的而且是频繁,如果一次或者两次在 ...
- android中app卡顿优化问题
所谓app卡顿原因就是在运行时出现了丢帧,还可能是UI线程被阻塞.首先来一下丢帧现象,android每16ms会对界面进行一次渲染,如果app的绘制.计算等超过了16ms那么只能等下一个16ms才能 ...
随机推荐
- OpenCL 存储器次序的验证
▶ <OpenCL异构并行编程实战>P224 的代码,先放上来,坐等新设备到了再执行 //kernel.cl __global ); // 全局原子对象 __kernel void mem ...
- nodejs 获取文件夹中所有文件、图片 名
//获取项目工程里的图片 var fs = require('fs');//引用文件系统模块 var image = require("imageinfo"); //引用image ...
- 使用seaborn制图(小提琴图)
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns # 设置风格, ...
- Spring @Trasactionl 失效, JDK,CGLIB动态代理
@Transaction: http://blog.csdn.net/bao19901210/article/details/41724355 Spring上下文: http://blog.csd ...
- jsfl 改变舞台宽高
fl.getDocumentDOM().height= 680; fl.getDocumentDOM().width= 550;
- Cachefiled
NFS不同共享客户端间的数据不同步 问题现象 当您用台ECS挂载同一个NFS文件系统,在ECS-A上append写文件,在ECS-B用tail -f观察文件内容的变化.在ECS-A写完之后,在ECS- ...
- TCP/IP知识总结(TCP/IP协议族读书笔记四)
参考:http://blog.chinaunix.net/uid-26275986-id-4109679.html 继续!TCP的流量控制和拥塞控制. TCP相对UDP可靠的地方在于它的拥塞控制.流量 ...
- Social media users of the world unite!
Social media users of the world unite!全世界社交媒体用户联合起来!If Plato were alive today, he might well regard ...
- win10下关于apache配置虚拟主机
apache安装完默认是不开启虚拟服务器的,如果希望在本地apache上面配置虚拟服务器,类似于在网上买的虚拟主机,可以按照以下步骤进行配置: 1,修改本机的hosts文件,如下 示例:127.0.0 ...
- moco入门
前提:moco是什么?有什么用 Moco是针对HTTP集成而生的,不过,现在也有人把它用在其它需要一个模拟服务器的场景中.比如,在移动开发中,有人开发一个移动应用,需要有一个远端服务,但在开发时,这个 ...