由code定义XML的视图 [英] Define a view of a XML by code
本文介绍了由code定义XML的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这就像在活动框架XML文件。我想设置我的XML添加视图,但是当我尝试它显示什么。
I've a XML File that acts like a frame for the activities. I want to set the View I've added in the XML, but when I try it nothing is shown.
<View
android:id="@+id/marco_container"
style="@style/wrapFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
这是我的活动code:
This is my Activity code:
setContentView(R.layout.marco);
LinearLayout li = (LinearLayout) findViewById(R.id.marco_container);
View view = View.inflate(getApplicationContext(), R.layout.prueba, null);
li.addView(view);
我如何查看添加到XML?
How can I add the View to the XML?
推荐答案
您必须使用 LayoutInflater
。是这样的:
You must use LayoutInflater
. Something like:
setContentView(R.layout.marco);
LinearLayout li = (LinearLayout) findViewById(R.id.marco_container);
View view = getLayoutInflater().inflate(R.layout.prueba, li, false);
li.addView(view);
这篇关于由code定义XML的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文