英文:
What is the LayoutInflater in Android? How does it differs from findViewById?
问题
以下是翻译好的部分:
"在Android中的一个LayoutInflater
示例代码:
View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.,parent,false);
无法理解LayoutInflater
在Android中的工作原理。尝试阅读Android的官方文档,但无法理解概念。"
英文:
An example LayoutInflater
code:
View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.,parent,false);
Can't understand the work of LayoutInflater
in Android. Tried to read the official documentation of the android but, couldn't get the concept.
答案1
得分: 0
findViewById和LayoutInflater之间的主要区别在于,findViewById用于访问布局中的现有视图,而LayoutInflater用于从XML布局文件创建新的视图层次结构。
findViewById是Activity类的一个方法,而LayoutInflater是一个独立的类。
findViewById用于访问当前布局中的视图,这意味着我们可以从XML中查找视图,并返回对其Java对象的引用,而LayoutInflater用于从XML布局文件创建新的视图层次结构,因此该类负责“膨胀”布局。
希望这有所帮助。
英文:
The main difference between findViewById and LayoutInflater is that findViewById is used to access existing views in a layout, while LayoutInflater is used to create a new view hierarchy from an XML layout file.
FindViewById is a method of the Activity class, while LayoutInflater is a separate class on it's own.
FindViewById is used to access a view in the current layout, this means lets us find Views from layouts written in XML and returns a reference to their Java objects, while LayoutInflater is used to create a new view hierarchy from an XML layout file, so this class is the responsible for “inflating” the layouts.
Hope it helps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论