我有这个观点:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/page_exlain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text here"
android:layout_marginTop ="20dp"
/>
<TextView
android:id="@+id/exec_summary_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/light_best_blue"
android:layout_marginTop ="10dp"
android:text="1) EXECUTIVE SUMMARY"
/>
<TextView
android:id="@+id/exec_summary_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text goes here."
android:layout_marginTop ="10dp"
/>
<TextView
android:id="@+id/product_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/light_best_blue"
android:layout_marginTop ="10dp"
android:text="2) YOUR PRODUCT OR SERVICE"
/>
<TextView
android:id="@+id/product_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text goes here......"
android:layout_marginTop ="10dp"
/>
</ScrollView>
</LinearLayout>
这次崩溃。知道为什么吗?我不知道如何使整个页面可滚动。
谢谢!
答案 0 :(得分:3)
scrollview只能有一个直接子项
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/page_exlain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text here"
android:layout_marginTop ="20dp"
/>
<TextView
android:id="@+id/exec_summary_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/light_best_blue"
android:layout_marginTop ="10dp"
android:text="1) EXECUTIVE SUMMARY"
/>
<TextView
android:id="@+id/exec_summary_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text goes here."
android:layout_marginTop ="10dp"
/>
<TextView
android:id="@+id/product_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/light_best_blue"
android:layout_marginTop ="10dp"
android:text="2) YOUR PRODUCT OR SERVICE"
/>
<TextView
android:id="@+id/product_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text goes here......"
android:layout_marginTop ="10dp"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
答案 1 :(得分:2)
像这样使用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/page_exlain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text here"
android:layout_marginTop ="20dp"
/>
<TextView
android:id="@+id/exec_summary_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/light_best_blue"
android:layout_marginTop ="10dp"
android:text="1) EXECUTIVE SUMMARY"
/>
<TextView
android:id="@+id/exec_summary_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text goes here."
android:layout_marginTop ="10dp"
/>
<TextView
android:id="@+id/product_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/light_best_blue"
android:layout_marginTop ="10dp"
android:text="2) YOUR PRODUCT OR SERVICE"
/>
<TextView
android:id="@+id/product_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text goes here......"
android:layout_marginTop ="10dp"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
原因是Android中的ScrollView
一次只能容纳1个孩子。所以你必须将你想要在容器中滚动的所有TextView
放在容器中再次LinearLayout
。
答案 2 :(得分:2)
您需要将文字视图放在另一个布局中,例如:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/page_exlain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text here"
android:layout_marginTop ="20dp"
/>
<TextView
android:id="@+id/exec_summary_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/light_best_blue"
android:layout_marginTop ="10dp"
android:text="1) EXECUTIVE SUMMARY"
/>
<TextView
android:id="@+id/exec_summary_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text goes here."
android:layout_marginTop ="10dp"
/>
<TextView
android:id="@+id/product_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/light_best_blue"
android:layout_marginTop ="10dp"
android:text="2) YOUR PRODUCT OR SERVICE"
/>
<TextView
android:id="@+id/product_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lots of text goes here......"
android:layout_marginTop ="10dp"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
(您需要删除Scrollview上的行xmlns:android="http://schemas.android.com/apk/res/android"
)
答案 3 :(得分:0)