【发布时间】:2012-02-27 06:35:05
【问题描述】:
在查找inflate 之后,我发现很难理解根视图的含义。它只是这个生成的 xml 层次结构的父视图还是整个视图层次结构的最上层视图。
我认为答案很可能是前者。但我面临一个问题。如果在我无法获得这个生成的层次结构的父视图的情况下,我是否必须在每次膨胀层次结构树时设置布局参数?
这是我的代码。并且 LinearLayout 无法填充父级。我认为LinearLayout的layout_height和layout_width必须设置为wrap_content。
storage_status.xml
<?xml version="1.0" encoding="utf-8"?>
<com.android.contacts.StorageStatusView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<View
android:layout_height="50px"
android:layout_width="50px"
android:background="#f00"/>
</com.android.contacts.StorageStatusView>
java 文件中的片段。
private class QuickActionClickListener implements QuickAction.OnActionItemClickListener {
@Override
public void onItemClick(QuickAction source, int pos, int actionId) {
switch (actionId) {
case ACTION_ID_STORAGE_STATUS :
final LayoutInflater inflater = getLayoutInflater();
new AlertDialog.Builder(ContactsListActivity.this)
.setTitle(UIUtils.getString(ContactsListActivity.this, R.string.storage_status))
.setView(inflater.inflate(R.layout.storage_status, null))
.show();
break;
}
}
}
提前致谢。对不起,我的英语很差。
【问题讨论】:
-
我发现以前有人问过这个问题。答案很明确。 stackoverflow.com/questions/5026926/…
标签: android