我无法在运行时向我的活动的主布局添加子布局。更准确地说,当我调用setContentView(layout)或layout.add(mySubLayout)时,我得到一个空指针异常,其中布局由findViewById(R.id.idLay)检索。下面是xml代码。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/idLay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
tools:context=".TrainingActy" >
似乎不可能修改静态创建的布局。但是我看到堆栈溢出的答案似乎可以做我想做的事,而且我从来没有在 android 的文档中读过关于不可能做到这一点的任何内容。