我正在尝试制作有滚动视图的动态布局。在滚动视图中,我添加了引用 main.xml 的垂直线性布局。代码立即停止,我尝试添加引用 main.xml 的布局。
ScrollView scroll;
EditText search;
Button checkin;
LinearLayout vt;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
scroll=new ScrollView(getApplicationContext());
vt=(LinearLayout) findViewById(R.id.llv);///referencing linear layout located in main.xml.This is where problem the is occurring.
//vt.setOrientation(LinearLayout.VERTICAL);
scroll.addView(vt);
this.setContentView(scroll);
}
main.xml(R.id.llv 所在的位置)
<?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" >
<LinearLayout
android:id="@+id/llv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ToggleButton" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</LinearLayout>