LayoutInflater与findViewById的用法有很多可比较之处。
如:他们都可以通过id返回View。
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_dialog,null);
Button button = (Button) findViewById(R.id.button);
不同之处是:LayoutInflater是用来实例化整个布局文件,而findViewById()是实例化布局文中中的View。
本文详细对比了LayoutInflater与findViewById的功能及使用方法。LayoutInflater用于实例化整个布局文件,而findViewById则用于从已加载的布局中获取特定的View组件。

1万+

被折叠的 条评论
为什么被折叠?



