2012-04-21 50 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