方法 inflate(int resource, ViewGroup root, boolean attachToRoot) 中,前连个参数都好理解,我比较费解的是第3个参数。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<FrameLayout
android:id="@+id/ffff"
android:layout_width="match_parent"
android:layout_height="wrap_content"></FrameLayout>
</LinearLayout>
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
</LinearLayout>
|
setContentView(R.layout.main);
ViewGroup v =
(ViewGroup) findViewById(R.id.ffff);
View vv = LayoutInflater.from(this).inflate(R.layout.ffff, v);
|
View vv = LayoutInflater.from(this).inflate(R.layout.ffff, v, false); |
ViewGroup v =
(ViewGroup) findViewById(R.id.ffff);
View vv = LayoutInflater.from(this).inflate(R.layout.ffff, v, false);
v.addView(vv);
|