当前位置:网站首页>自定义View注意事项
自定义View注意事项
2022-07-19 22:27:00 【小刘学安卓】
主要是总结一下“Anroid 开发艺术探索”中第4.4.2小节那一大段话,梳理出一个图方便自己记忆,和理解为什么需要注意这些点。
1、为什么在自定义View的onMeasure()中处理wrap_content。
这个之前的文章就已经说过了,可以看以前的问题。
2、为什么在ViewGroup中onMeasure()和onLayout()中处理padding和子元素的margin值。
在测量和布局过程中需要考虑padding值和子view的margin值,才能测量出子view的大小。在计算viewgroup剩余空间时需要考虑padding和margin。(写的啥也不是,后面看源码再补充吧)
3、为什么需要在onDraw()方法中处理padding呢?
onDraw()已经知道view的宽高,则在绘制内容时,就需要考虑padding的值。让绘制内容距离view的边框有padding的距离。这样padding属性才生效了。
边栏推荐
猜你喜欢
How to use sublime text to open MD instead of typora
Unity_同个材质多个颜色内存优化——使用MaterialPropertyBlock
132天...从电子厂流水线走到了高薪程序员
ECCV 2022 | 重新思考Vision Transformers中用于数据增强的图像混合
Opencv learning notes - threshold
Emergency response > > types and disposal methods of network security emergency events
牛市还在,资金往头部集中是全球性规律 2021-04-04
Can we still buy in the bull market? 2021-04-09
抖音联手爱奇艺,能否打开另一个新空间?
Successfully solved @keyup Enter= "search()" problems that do not take effect in the El input component
随机推荐
如何提升网络安全应急响应与事件处置能力
[机缘参悟-47]:鬼谷子-第十一决篇-决策者,中庸也,利益合理化分配也
Typescript正则表达式使用
Successfully solved @keyup Enter= "search()" problems that do not take effect in the El input component
MySQL transaction
Programmer growth Chapter 22: how to lead a team?
阿里P8晒1月工资条,看完真的狠狠扎心了…
Bank ATM deposit and withdrawal system (implemented in C language)
【LeetCode每日一题——消失的数字】
Qudian prefabricated dish brand strategy press conference
成功 解决 @keyup.enter=“search()“ 在el-input 组件中不生效的问题
软件研发效能度量的成功要素
Security-001
M matlab performance simulation of optical fiber communication system based on Fiber Bragg grating sensor network connected to GPON, including decoding, unpacking, demultiplexing, rate recovery, frami
微服务架构 | 链路追踪 - [Sleuth]
牛市逃顶,值得注意的关键信号 2021-04-14
There is still a lot of room for innovation in defi, and high-quality projects will appear in the future 2021-04-13
多线程进阶篇Step2
Comparison of several popular cross end technology solutions in 2022
LeetCode 题集 SQL (一)