安卓UI面试题 41-45

41. View.inflate和LayoutInflater.inflate的区别?

实际上没有区别,View.inflate实际上是对LayoutInflater.inflate做了一层包装,
在功能上,LayoutInflate功能更加强大。

View.inflate实际上最终调用的还是LayoutInflater.inflate
(@LayoutRes int resource, @nullable ViewGroup root)三个参数的方法,
这里如果传入的root如果不为空,
那么解析出来的View会被添加到这个ViewGroup当中去。

而LayoutInflater.inflate方法则可以指定当前View是否需要添加到ViewGroup中去。

42. 简述invalidate()和postInvalidate()方法的区别和应用场景?

invalidate()用来重绘UI,需要在UI线程调用。

postInvalidate()也是用来重新绘制UI,它可以在UI线程调用,
也可以在子线程中调用postInvalidate()方法内部通过Handler发送了
一个消息将线程切回到UI线程通知重新绘制,并不是说postInvalidate()
可以在子线程更新UI,本质上还是在UI线程发生重绘,
只不过我们使用postInvalidate()它内部会帮我们切换线程


/**
*Cause an invalidate to happen on a
* subsequent cycle through the event loop.
* Use this to invalidate the View from a
* non-UI thread.
*
*
This method can be invoked from
* outside of the UI thread
* only 

相关推荐

  1. UI面试 41-45

    2024-03-20 00:34:06       40 阅读
  2. UI面试 45-50

    2024-03-20 00:34:06       38 阅读
  3. UI面试 36-40

    2024-03-20 00:34:06       34 阅读
  4. 面试多线程41-45

    2024-03-20 00:34:06       31 阅读
  5. Kotlin面试 41-50

    2024-03-20 00:34:06       36 阅读
  6. 面试网络知识基础 41-45

    2024-03-20 00:34:06       50 阅读
  7. Kotlin 面试 31-40

    2024-03-20 00:34:06       44 阅读
  8. IOS面试编程机制 41-45

    2024-03-20 00:34:06       37 阅读
  9. UI面试 31-35

    2024-03-20 00:34:06       39 阅读
  10. UI面试 51-55

    2024-03-20 00:34:06       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-20 00:34:06       91 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-20 00:34:06       97 阅读
  3. 在Django里面运行非项目文件

    2024-03-20 00:34:06       78 阅读
  4. Python语言-面向对象

    2024-03-20 00:34:06       88 阅读

热门阅读

  1. 遍历list过程中调用remove方法

    2024-03-20 00:34:06       33 阅读
  2. IOS面试题object-c 116-120

    2024-03-20 00:34:06       36 阅读
  3. ZCC5429 异步升压芯片

    2024-03-20 00:34:06       41 阅读
  4. 学完Efficient c++ (46-47)

    2024-03-20 00:34:06       44 阅读
  5. MyBatis:枚举类型与字符串比较

    2024-03-20 00:34:06       45 阅读
  6. opencv4 如何截取子图象

    2024-03-20 00:34:06       41 阅读
  7. 思科防火墙如何配置静态NAT

    2024-03-20 00:34:06       37 阅读
  8. 作用域(词法作用域)

    2024-03-20 00:34:06       38 阅读
  9. 聚合函数和GROUP BY

    2024-03-20 00:34:06       40 阅读
  10. LeetCode第389场周赛个人题解

    2024-03-20 00:34:06       49 阅读