2012-06-07 16 views
1

這裏我展示了我的應用程序的xml佈局。我想使用Scrollview滾動整個頁面。但我無法使用。ScrollView只支持一個直接的孩子。但我想滾動整個content.please幫助我解決這個問題?如果ScrollView只支持一個直接子,如何顯示整個佈局可滾動?

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" android:layout_width="match_parent" 
    android:orientation="vertical" 
    > 


      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center_horizontal" 
       android:orientation="horizontal" > 

      <ImageButton 
       android:id="@+id/prev" 
       android:layout_width="40dp" 
       android:layout_height="40dp" 
       android:layout_gravity="left" 
       android:background="@null" 
       android:src="@drawable/left_white" /> 

      <EditText 
       android:layout_width="185dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginLeft="25dp" 
       android:hint="" 
       android:visibility="invisible" 
       /> 

      <ImageButton 
       android:id="@+id/tour" 
       android:layout_width="50dp" 
       android:layout_height="50dp" 
       android:layout_gravity="right" 
       android:layout_marginLeft="17dp" 
       android:background="@null" 
       android:src="@drawable/logo" /> 

      </LinearLayout> 
         <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:layout_gravity="center" 
       > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="What interests you?" 
     android:textSize="20dp" > 

</TextView> 
</LinearLayout> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="fill_horizontal" 
       android:orientation="horizontal" 
       > 

       <com.android.example.CoverFlow 
        android:id="@+id/coverFlow" 
        android:layout_width="match_parent" 
        android:layout_height="150dip"/> 

      </LinearLayout> 
<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_marginTop="17dp" 
    > 

</LinearLayout> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ListView 
     android:id="@+id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:divider="#b5b5b5" 
     android:dividerHeight="1dp" 
     android:listSelector="@drawable/list_selector" /> 

</LinearLayout> 

</LinearLayout> 

回答

1

,你可以做你的主要的LinearLayout在此之前

<your main layout>  
<ScrollView> 
<LinearLayout> 

your whole layout code here 
</LinearLayout> 
</Scrollview> 
</your main layout> 
+0

我想我已經明確提到你必須在主佈局後添加滾動視圖 – Siddhesh

2

戴上滾動視圖。

<LinearLayout> 
    <ScrollView> 
     <LinearLayout> 
      // This Linear Layout contains your entire layout code 
     </LinearLayout> 
    </Scrollview> 
    </LinearLayout> 
+0

如果我在主佈局中放置滾動視圖,佈局無法顯示。 – rajeshlawrance

+0

@rajeshlawrance我編輯我的答案,請檢查它,並請告訴我你的代碼。 –

+0

已經把我的代碼放在我的問題 – rajeshlawrance

0

同意。它只支持一個孩子。但是,如果您希望上述xml文件可滾動,請將主要的Linearlayout放入scrollView標籤內。主LinearLayout將被視爲ScrollView的單個子項。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" android:layout_width="match_parent" 
    android:orientation="vertical" 
    > 
    <LinearLayout 
    android:layout_height="match_parent" android:layout_width="match_parent" 
    android:orientation="vertical" 
    > 
    ... 
</ScrollView> 
+0

我改變了,但還沒來come.i沒有得到滾動視圖 – rajeshlawrance

+0

問題在於,即使您能夠使用ScrollView作爲父佈局,因爲您在使用Linearlayout中的List時,您不應該也不能使用ScrollView,因爲ScrollView和列表都具有滾動功能,您不應誇大ScrollView內的列表。既然你使用的是列表,你不需要在這裏使用ScrollView。\ – Shrikant

+0

yes.as你說,你是正確的,它有可能或如何改變? – rajeshlawrance

0
<?xml version="1.0" encoding="utf-8"?> 

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:orientation="vertical" > 

    <!-- add your entire layout here --> 



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="match_parent" android:layout_width="match_parent" 
     android:orientation="vertical"> 


       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center_horizontal" 
        android:orientation="horizontal" > 

       <ImageButton 
        android:id="@+id/prev" 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:layout_gravity="left" 
        android:background="@null" 
        android:src="@drawable/left_white" /> 

       <EditText 
        android:layout_width="185dp" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginLeft="25dp" 
        android:hint="" 
        android:visibility="invisible" 
        /> 

       <ImageButton 
        android:id="@+id/tour" 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:layout_gravity="right" 
        android:layout_marginLeft="17dp" 
        android:background="@null" 
        android:src="@drawable/logo" /> 

       </LinearLayout> 
          <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" 
        android:layout_gravity="center" 
        > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="What interests you?" 
      android:textSize="20dp" > 

    </TextView> 
    </LinearLayout> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="fill_horizontal" 
        android:orientation="horizontal" 
        > 

        <com.android.example.CoverFlow 
         android:id="@+id/coverFlow" 
         android:layout_width="match_parent" 
         android:layout_height="150dip"/> 

       </LinearLayout> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginTop="17dp" 
     > 

    </LinearLayout> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <ListView 
      android:id="@+id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:divider="#b5b5b5" 
      android:dividerHeight="1dp" 
      android:listSelector="@drawable/list_selector" /> 

    </LinearLayout> 

    </LinearLayout> 

    </ScrollView> 
+0

我得到了錯誤行開始於<?xml version =「1.0」encoding =「utf-8」?>不允許處理指令目標匹配「[xX] [mM] [lL]」。 – rajeshlawrance

+0

哦...即使我改變了也有同樣的錯誤 – rajeshlawrance

0

不能使用的ListView裏面滾動型。我們很多人都有這個問題。因此,這裏是這個問題的解決方案:

  1. 創建list.xml只包含的ListView
  2. 創建header.xml包含的ListView的XML代碼
  3. 創建以上footer.xml包含下面的ListView的XML代碼

最後,從你的主類抓取ListView引用並添加列表Hea der和Footer。希望這會起作用。如果您有任何問題,請確保您的評論。

相關問題