Android view 的cache

layercache:简化了Android和Java的缓存 立即下载

1 View 相关的六个个函数分别如下:
public void setDrawingCacheEnabled (boolean enabled)  API Level1
Enables or disables the drawing cache. When the drawing cache is enabled, the next call to getDrawingCache() or buildDrawingCache() will draw the view in a bitmap. Calling draw(android.graphics.Canvas) will not draw from the cache when the cache is enabled. To benefit from the cache, you must request the drawing cache by calling getDrawingCache() and draw it on screen if the returned bitmap is not null.

Enabling the drawing cache is similar to setting a layer when hardware acceleration is turned off. When hardware acceleration is turned on, enabling the drawing cache has no effect on rendering because the system uses a different mechanism for acceleration which ignores the flag. If you want to use a Bitmap for the view, even when hardware acceleration is enabled, see setLayerType(int, android.graphics.Paint) for information on how to enable software and hardware layers.

This API can be used to manually generate a bitmap copy of this view, by setting the flag to true and calling getDrawingCache().

public Bitmap getDrawingCache ()    API Level1
Calling this method is equivalent to calling getDrawingCache(false)

public Bitmap getDrawingCache (boolean autoScale)   API Level4
Returns the bitmap in which this view drawing is cached. The returned bitmap is null when caching is disabled. If caching is enabled and the cache is not ready, this method will create it. Calling draw(android.graphics.Canvas) will not draw from the cache when the cache is enabled. To benefit from the cache, you must request the drawing cache by calling this method and draw it on screen if the returned bitmap is not null.

Note about auto scaling in compatibility mode: When auto scaling is not enabled, this method will create a bitmap of the same size as this view. Because this bitmap will be drawn scaled by the parent ViewGroup, the result on screen might show scaling artifacts. To avoid such artifacts, you should call this method by setting the auto scaling to true. Doing so, however, will generate a bitmap of a different size than the view. This implies that your application must be able to handle this size.

public void buildDrawingCache ()    API Level1
Calling this method is equivalent to calling buildDrawingCache(false).

public void buildDrawingCache (boolean autoScale)   API Level4
Forces the drawing cache to be built if the drawing cache is invalid.

If you call buildDrawingCache() manually without calling setDrawingCacheEnabled(true), you should cleanup the cache by calling destroyDrawingCache() afterwards.

Note about auto scaling in compatibility mode: When auto scaling is not enabled, this method will create a bitmap of the same size as this view. Because this bitmap will be drawn scaled by the parent ViewGroup, the result on screen might show scaling artifacts. To avoid such artifacts, you should call this method by setting the auto scaling to true. Doing so, however, will generate a bitmap of a different size than the view. This implies that your application must be able to handle this size.

You should avoid calling this method when hardware acceleration is enabled. If you do not need the drawing cache bitmap, calling this method will increase memory usage and cause the view to be rendered in software once, thus negatively impacting performance.

public void destroyDrawingCache ()  API Level1
Frees the resources used by the drawing cache. If you call buildDrawingCache() manually without calling setDrawingCacheEnabled(true), you should cleanup the cache with this method afterwards.

首先要获得view的cache, 通过setDrawingCacheEnabled(true)方法开启cache, 然后调用getDrawingCache()方法就可以获得view的cache 图片了。如果调用setDrawingCacheEnabled(false),系统也会自动把原来的cache销毁掉;

注意:buildDrawingCache()方法可以不用调用,原因在于getDrawingCache方法时,如果view的cache没有建立,会自动调用buildDrawingCache方法以生成cache.

如果要更新cache, 必须要调用destroyDrawingCache方法把旧的cache销毁,这样后面才能建立新cache,具体的方法:
1)destoryDrawingCache()
2)setDrawingCacheEnabled(false)
都可以。

获取view 的cache demo:
View view = view.setDrawingCacheEnabled(true)
Bitmap bp = view.getDrawingCache();

2 ViewGroup 涉及到cache的两个方法
protected void setChildrenDrawingCacheEnabled (boolean enabled)
Enables or disables the drawing cache for each child of this view group.

protected void setChildrenDrawnWithCacheEnabled (boolean enabled)
Tells the ViewGroup to draw its children using their drawing cache. This property is ignored when isAlwaysDrawnWithCacheEnabled() is true. A child's drawing cache will be used only if it has been enabled. Subclasses should call this method to start and stop using the drawing cache when they perform performance sensitive operations, like scrolling or animating.

setChildrenDrawingCacheEnabled方法,可以使viewgroup里的所有子view开启cache;而setChildrenDrawWithCacheEnabled使在绘制子view时,如果子view开启了cache, 则使用它的cache进行绘制,从而节省了绘制时间;

碳酸钙岩石酸蚀酸溶COMSOL建模:非均质对酸蚀通道的影响 多孔介质中的流动与化学反应耦合是石油工程和地下资源开发中的核心问题,酸液与岩石矿物的溶蚀过程直接关系到酸化增产效果。在碳酸盐岩储层中,盐酸与方解石的反应速率极快,酸液会优先沿高渗透区域推进,形成指状酸蚀通道,即wormhole。传统均质模型难以描述这种局部溶蚀行为,而数值模拟工具COMSOL通过耦合达西定律、稀物质传递与孔隙度演化方程,能够定量刻画酸蚀路径与渗透率的变化规律。工程实践中,模拟结果可用于预测酸液突破体积、优化注入排量,并为基质酸化方案设计提供依据。本文围绕碳酸钙岩石酸蚀酸溶COMSOL模型,探 阅读详情

相关推荐

Imputation Methods for scRNA Sequencing Data

越来越多的研究者使用单细胞RNA测序(scRNA-seq)技术来表征单细胞水平的转录图谱。他们用它来研究复杂组织的异质性、转录组动力学和未知生物的多样性。然而,在基因表达模式随机性的scRNA-seq数据中普遍存在许多技术和生物学上的噪音。这些数据通常具有高维、稀疏和大量“dropout”值的特点,并且受批处理效应的影响。scRNA-seq数据中大量的“dropout”值严重掩盖了基因之间的重要关系,阻碍了下游分析。因此,scRNA-seq数据dropout值的估算就显得尤为重要。

qq_34179307的博客 542

Android 取view的cache图片

view.setDrawingCacheEnabled(true); //启用绘制缓存 view.buildDrawingCache(); //可以不调用 get时会自动判断如果没有cache,会调用buildcache Bitmap drawingCache = view.getDrawingCache(); view.setDrawingCacheEnabled(

打渔还是晒网 —— stone 1174

基于simulink的变压器保护仿真设计【MATLAB源码+Word文档】

电力系统变压器保护MATLAB/simulink仿真设计。纵联差动保护-过电流保护-距离保护

weixin_761237174的博客 1271

Android应用优化(2)View cache的优化

在Android的显示机制中,View的软件渲染都是基于bitmap图片进行的处理。并且刷新机制中只要是与脏数据区有交集的视图都将重绘,所以在View的设计中就有一个cache的概念存在,这个cache无疑就是一个bitmap对象,它的存在本来是用来提高view绘制效率的,但是往往在应用的设计中也是一个影响性能的因素。 先看看关于cache概念的一些API吧,从中我们可以得到一些有效信息。

hehui1860的专栏 1623

Python接口自动化测试实战:Requests+Pytest+Excel+Allure框架搭建指南

接口自动化测试是现代软件工程中保障软件质量的关键实践,其核心原理是通过脚本模拟客户端请求,自动验证API的功能、性能和可靠性。在Python技术栈中,Requests库以其简洁的API成为处理HTTP请求的基石,而Pytest框架则凭借其灵活的Fixture机制和强大的参数化功能,为测试用例的组织与执行提供了优雅的解决方案。结合Excel进行数据驱动测试,能够有效实现测试数据与脚本逻辑的分离,提升协作效率;最终通过Allure生成可视化测试报告,清晰呈现测试结果与过程。这套技术组合(Requests, Py

weixin_28677451的博客 304

《从零搭建Vue3项目实战》(AI辅助搭建Vue3+ElemntPlus后台管理项目)零基础入门系列第一篇:开发环境准备

vue3入门实战:环境准备篇

感谢阅读 1385

使用Node.js完成的第一个项目的实践总结

node 目录(?)[+] 项目简介 这是一个资产管理项目,主要的目的就是实现对资产的无纸化管理。通过为每个资产生成二维码,来联合移动终端完成对资产的审核等。这个项目既提供了Web端的管理界面也提供移动端(Andorid)的资产审核、派发等相关功能。 我们用Node.js构建该项目的Web端以及移动端的Serveice API。 项目主框架:Express 简...

各研发管理 325

深度探索:VS2022 牵手 DeepSeek,开启开发新征程

通过将 VS2022 与 DeepSeek 接入,我们成功开启了智能开发的新征程。从前期的硬件准备、软件环境搭建,到实战环节的一步步配置与整合,再到全面的测试与验证,每一个步骤都充满挑战,但也带来了满满的收获。在实际应用中,VS2022 与 DeepSeek 的结合展现出了强大的优势,为开发者带来了更高的效率和更出色的代码质量。无论是代码自动补全、智能代码审查,还是自然语言交互编程,都让开发过程变得更加智能、便捷,极大地提升了开发体验。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 3524

node博客项目开发手记

NodeJs开发个人博客项目 预览地址:http://baijiawei.top GitHub地址:https://github.com/bjw1234/blog 需要安装的模块 body-parser 解析post请求 cookies 读写cookie express 搭建服务器 markdown Markdown语法解析生成器 mo...

weixin_34247299的博客 240

高通平台WIFI学习-- WCN7851 三频 2X2 MIMO DBS HBS Wi-Fi 7介绍

WCN7851是支持Wi-Fi 7和蓝牙5.4的三频SoC芯片,具有以下核心特性:采用NSP334封装,支持2.4GHz/5GHz/6GHz三频段并发操作,最高速率达5.8Gbps;集成MU-MIMO、4096QAM调制技术,6GHz频段支持320MHz带宽;提供PCIe Gen3接口和低功耗设计,兼容多种无线标准。电气特性包括1.8V/1.2V可编程GPIO、76.8MHz时钟源要求,以及详细的射频性能参数。该芯片通过多链路操作和动态频率选择等先进功能,实现高性能无线连接。

专业开发者的博客,一个从事Android WiFi和蓝牙的工程师 1276

【华为OD机试真题】6、数组去重和排序 | 机试真题+思路参考+代码解析(C++、Java、Py、C语言、JS)

题目描述 >给定一个乱序的数组,删除所有的重复元素,使得每个元素只出现一次,并且按照出现的次数从高到低进行排序,相同出现次数按照第一次出现顺序进行先后排序

KJ.JK 3888

drawingcache解析 通过view的绘制缓存得到bitmap,从而实现view内容截图

android为了提高滚动等各方面的绘制速度,可以为每一个view建立一个缓存,使用 View.buildDrawingCache为自己的view建立相应的缓存,这个cache就是一个bitmap对象。利用这个功能可以对整个屏幕视图进行截屏并生成Bitmap,也可以获得指定的view的Bitmap对象。在有的时候还会影响性能,例如如果自己实现一个Gallery效果,可能就会使用到view缓存。an

dongbaoming的博客 1万+

Transformer实战——Transformer自编码模型

自编码模型依赖于原始 Transformer 编码器,并且在解决分类问题时非常高效。除了 BERT 外,还有许多流行的自编码模型,在本节中,我们将一些除 BERT 外的自编码模型,这些模型的目标是通过优化预训练过程、增加层数或头数、改善数据质量、设计更好的目标函数等,来在下游任务上取得更好的表现。这些改进大致可以分为两个方面,更好的架构设计选择和预训练控制。

盼小辉丶的博客 9327

Android中通过Cache机制获取View的绘图层

要获取view的cache先要通过setDrawingCacheEnable方法把cache开启,然后再调用getDrawingCache方法就可 以获得view的cache图片了。buildDrawingCache方法可以不调用,因为调用getDrawingCache方法时,若果 cache没有建立,系统会自动调用buildDrawingCache方法生成cache。若果要更新cache, 必须

sqyNick 779

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Android 使用Cache机制

有时候在一个应用程序中我们突然发现这个应用程序的View特别好看,我们想把它保存为图片保存在手机上,这时候我们该如何做呢?      在View中可以使用Cache机制将View上的内容保存为Bitmap。   如何获得Cache我们先看如下几个方法: void setDrawingCacheEnabled(boolean flag):设置该View可生成Cache.Bitmap get

To_be_Designer 3571

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Android将View或文字保存成图像

方法1 使用Drawing Cache 直接上代码吧 View view = findViewById(R.id.testview); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); //设置背景色 v...

VivianLab 376

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

android画布保存为bitmap,Android实现将View保存成Bitmap的方法

本文实例讲述了Android实现将View保存成Bitmap的方法。分享给大家供大家参考,具体如下:1、public Bitmap convertViewToBitmap(View view){Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),view.getHeight(),Bitmap.Config.ARGB_8888);//利用bitma...

weixin_29207439的博客 704

android 屏幕 view,Android屏幕及view的截图实例详解

Android屏幕及view的截图实例详解发布时间:2020-09-18 19:26:14来源:脚本之家阅读:102作者:笨鸟-先飞Android屏幕及view的截图实例详解屏幕可见区域的截图整个屏幕截图的话可以用View view = getWindow().getDecorView();public static Bitmap getNormalViewScreenshot(View view...

weixin_39869959的博客 214

android把一个view生成bit,Android中View转换为Bitmap及getDrawingCache=null的处理方法

1.前言Android中经常会遇到把View转换为Bitmap的情形,比方,对整个屏幕视图进行截屏并生成图片;Coverflow中需要把一页一页的view转换为Bitmap、以便实现复杂的图形效果(阴影、倒影效果等);再比方少量动态的实时View为便于观察和记录数据、需要临时生成静态的Bitmap。2.实现方法1)下面是笔者经常用的一个转换方法 public static Bitmap co...

weixin_39629780的博客 179

该View转换成Bitmap方法

方法一: /** * 该View绘制到Bitmap上 * @param view 须要绘制的View * @param width 该View的宽度 * @param height 该View的高度 * @return 返回Bitmap对象 * add by csj 13-11-6 */ public Bitmap getViewBitmap(View comBitmap...

weixin_34344677的博客 69

Android RecyclerView和ListView

1.ListView ListView是不强制我们实现ViewHolder的,但是后来google建议我们实现ViewHolder模式。先分别看一下这两种不同的方式。 不使用ViewHolder的模式: 使用ViewHolder的模式: 注意用红框标出来的部分,ListView使用ViewHolder的好处就在于可以避免每次getView都进行findViewById()操作,因为findViewById()利用的是DFS算法(深度优化搜索),是非常耗性能的。而对于RecyclerView来说,强制实现

zenmela2011的专栏 1616

View转换成Bitmap

public static Bitmap getViewBitmap(View v) { if (v == null) { return null; } try { v.clearFocus(); // v.setPressed(false); //

YyuTtian0523的博客 456

将View兑换Bitmap

/** * 中间View保罗转化成Bitmap * */ private Bitmap saveViewBitmap(View view) { // get current view bitmap view.setDrawingCacheEnabled(true); view.buildDrawingCache(true); Bitmap bit...

weixin_30763455的博客 61

Android实现多页左右滑动效果,支持子view动态创建和cache

要实现多页滑动效果,主要是需要处理onTouchEvent和onInterceptTouchEvent,要处理好touch事件的子控件和父控件的传递问题。 滚动控制可以利用android的Scroller来实现。 这里提供两种做法: 1、自定义MFlipper控件,从ViewGroup继承,利用Scroller实现滚动,重点是onTouchEvent和onInterceptT...

weixin_30522095的博客 104

Android 截图,截取指定view截图

二、具体实现方式   实用截图方法截取整个activity public static Bitmap shotActivity(Activity ctx) { View view = ctx.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache()...

meixi_android的博客 4802

Android源码--Launcher笔记之屏幕截图

1. android截屏代码 private Bitmap getViewBitmap(View v) {         v.clearFocus();                            //清除视图焦点         v.setPressed(false);                  //将视图设为不可点击         boolean wi

wre_most2的专栏 1163
上一篇: bash脚本,自动输入sudo的密码
下一篇: Android Animation动画
Superr爬爬虫
博客等级 码龄19年 72粉丝 93原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值