android - Android 应用程序开发中的充气器

标签 android

谁能告诉我 Inflator 是什么以及如何在 Android 应用程序中使用它?

我不知道它的确切用途以及为什么要使用它。

最佳答案

我首选的处理通货膨胀的方法:

//First get our inflater ready, you'll need the application/activity context for this
LayoutInflater mInflater;
mInflater = LayoutInflater.from(mContext);

//Inflate the view from xml
View newView = mInflater.inflate(R.layout.my_new_layout, null);

//Then you'll want to add it to an existing layout object
mMainLayout.add(newView);

//Or perhaps just set it as the main view (though this method can also 
// inflate the XML for you if you give it the resource id directly)
setContentView(newView);

基本上,您可以使用它在运行时扩充现有的 xml 布局。通常您会继续将这些新 View 插入到先前定义的 ViewGroups 或 List 对象中。

关于android - Android 应用程序开发中的充气器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3861434/

相关文章:

android - Google GCM 实现是否需要 Api key

android - 如何在后台线程上运行 ListenableWorker 工作?

java - 如何从 onClick Java 调用类

java - 将大型交换机转换为哈希(或其他推荐)

java - 无法使用 HttpURLConnection 连接到 https

java - 如何仅传递用户选择的字符串

android - 什么类别/服务会为我提供有关 Android 上的纬度/经度组合的业务信息?

java - 在 SharedPreference 中保存通用类型的列表

android - 通过 android.widget.RemoteViewsService 访问时的 Content Provider 权限

java - 错误:Module 'com.squareup.assertj:assertj-android-recyclerview-v7:1.1.1' depends on one or more Android Libraries but is a jar