2012-04-21 47 views
0

我有这样的看法:Android的 - 试图让滚动视图,并导致崩溃

<?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

做了滚动 – 2012-04-21 14:50:51

回答

2

你需要把你的textviews在另一个布局,如:

<?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> 

(您需要删除滚动型线xmlns:android="http://schemas.android.com/apk/res/android"

3

滚动视图只能有一个直接子

<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> 
+0

子布局与此更换你的代码... – MAC 2012-04-21 14:53:59

+1

哇,比我早45秒。 – 2012-04-21 14:54:20

+0

谢谢,但它简化版,似乎工作....它不呈现文本视图元素。 – GeekedOut 2012-04-21 14:56:50

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

+0

这是正确的答案,并且是解决问题的正确方法。 – roboguy12 2012-04-21 14:53:57

+0

出于某种原因,在我的情况下,textview元素不显示:( – GeekedOut 2012-04-21 14:59:58

+0

@GeekedOut,请参阅我的答案... – amp 2012-04-21 15:03:44