2010-09-09 45 views
0

我的情況是這樣的:的Android的ListView並沒有擴張按計劃

<ScrollView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"  
    android:scrollbars="vertical"   
    android:background="#ffffeb"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="10dp"> 

     // Other stuff in between here.. 

     <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:paddingLeft="12dp" 
     android:paddingRight="12dp"> 

     <Button 
      android:id="@+id/insert_ad_ad_information_category_and_type_button" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="6dp" 
      android:text="@string/insert_ad_ad_information_category_and_type_button"/> 

     <ListView 
      android:id="@+id/insert_ad_ad_information_parameters_frame" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#ffffeb" 
      android:cacheColorHint="#00000000" 
      android:divider="#00000000" 
      android:dividerHeight="0dp" 
      android:scrollbars="none" 
      android:listSelector="@android:color/transparent"/> 

我的問題是,我不能讓我的ListView得到我想要的合適的高度。
我將添加幾個組件與我自定義的BaseAdapter類,並按照預期工作。
但是,當我然後調試我的應用程序時,我只能看到列表中的3個組件中的1.5個,其餘的在ListView中進一步隱藏。
但我怎樣才能讓我的ListView計算我有多少組件,並讓它直接顯示所有組件,而不必向下滾動?

另一個想法是,如果我可以使用我的BaseAdapter填充任何其他類型的視圖?因爲我使用ListView的唯一原因是因爲setAdapter()方法。

感謝所有的想法和意見:)

回答

1

你不能有一個滾動型的ListView。這就是問題所在。

+0

好的,謝謝。我可以如何解決我的問題的任何建議?我可以將BaseAdapter添加到另一種類型的視圖嗎? – 2010-09-09 12:46:52

+0

使用addHeader(View)&addFooter(View)給ListView,然後給它分配適配器(在內部它將標題,光標,頁腳包裝到一個新光標中) – 2010-09-10 02:57:28

+0

太好了。它像一個魅力! :D再次感謝。 – 2010-09-10 09:30:42

0

如前所述,您不能在ScrollView中使用ListView。 如果你想你的列表視圖有不同類型的項目,並滾動那些「普通」項目 你確實需要自定義適配器。如果您喜歡,可以將其基於BaseAdapter 適配器必須支持您的項目類型,併爲適當的佈局充氣,