我main.xml中布局只包含一个按钮和一个LinearLayout
content_area,其下面示出:为什么LayoutInflater在我的情况下不起作用?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/myBtns"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<Button
android:id="@+id/btn_one"
android:layout_width="100dip"
android:layout_height="30dip"
android:text="button one"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/content_area"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<!--inflate layout here-->
</LinearLayout>
</LinearLayout>
我有另一个布局(content_one.xml),其将被用来嵌入
content_one.xml:所述main.xml中布局的(膨胀)到(值id)content_area
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView.../>
...
<Button .../>
</LinearLayout>
我试图用LayoutInflater
嵌入content_one.xml到content_area
的main.xml中:
public class MyActivity extends Activity{
private LinearLayout contentArea;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
contentArea= (LinearLayout) findViewById(R.id.content_area);
LayoutInflater inflater = (LayoutInflater)MyActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflatedView = (View) inflater.inflate(R.layout.content_one, null);
contentArea.addView(inflatedView);
}
但它不工作,content_one.xml不显示content_area
的main.xml。我得到了以下错误信息从logcat的月食
(请鼠标右键点击下面的图片和视野图像上)
为什么我的LayoutInflater不工作?我错在哪里?
该日志不完整...粘贴整个日志(当然发生错误)...和文本不是图像。 – Cristian
@ Cristian,我不知道如何从eclipse LogCat控制台复制整个错误信息,但是我上传了另一个替换旧的图像 – Leem