我有一个UI,我动态构建它。我希望将某些组件放在XML资源文件中。所以我这样做:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+android:id/titreItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
我看到有关于在文件res/layout/titreitem.xml
中的内容,但我不知道如何将其放入我的用户界面中。因此,在activity.onCreate
中,我想要做一些类似以下的事情:
RelativeLayout myBigOne = new RelativeLayout(this);
TextView thingFromXML = [what here ? ];
myBigOne.addView(thingFromXML);
setContentView(myBigOne);