2013-03-26 83 views
1

滾動視圖內的listviews只顯示一個列表項?如何顯示所有列表項

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
    <TextView 
     android:id="@+id/section_one_header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="18dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="10dp" 
     android:singleLine="true" 
     android:text="Summary" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#51556C" 
     android:textSize="13sp" 
     android:textStyle="bold" /> 

    <ListView 
     android:id="@+id/section_list_view" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="5dp" > 
    </ListView> 

    <TextView 
     android:id="@+id/section_two_header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="18dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="10dp" 
     android:singleLine="true" 
     android:text="Data" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#51556C" 
     android:textSize="13sp" 
     android:textStyle="bold" > 
    </TextView> 

    <LinearLayout 
     android:id="@+id/eve_det" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="5dp" 
     android:background="@layout/style_evedetail" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/section_two_data" 
      android:layout_width="fill_parent" 
      android:layout_height="100dp" 
      android:layout_marginBottom="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:scrollbars="vertical" 
      android:textSize="10sp" > 
     </TextView> 

     <EditText 
      android:id="@+id/section_two_edit_text" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:focusableInTouchMode="true" 
      android:imeActionId="@+id/done_button" 
      android:imeActionLabel="done" 
      android:singleLine="true" /> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/section_three_header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="18dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="10dp" 
     android:text="Attachment" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#51556C" 
     android:textSize="13sp" 
     android:textStyle="bold" > 
    </TextView> 
    <ListView 
     android:id="@+id/attachment_list_view" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" /> 
</LinearLayout> 

這是在滾動視圖的代碼。在這裏,我需要顯示標題和相應的ListView,然後用編輯文本顯示TextView,然後再顯示標題和ListView。任何人都可以幫助我如何顯示兩個列表視圖中的所有列表項,或者任何人有其他想法幫助我。

+0

退房以下職位信息http://stackoverflow.com/questions/6210895/listview-inside添加頁眉/頁腳-scrollview-is-not-scrolling-on-android – 2013-03-26 11:35:11

回答

1

是的,因爲列表視圖具有默認滾動功能。如果您在另一個可滾動視圖(例如滾動視圖)內放置列表視圖。列表滾動會妨礙。

要避免這種情況,列表視圖具有頁眉和頁腳視圖的概念。

您可以將n個頁眉和頁腳添加到列表中。

下面是一個示例代碼段如何通過虛報任何XML佈局,它

LayoutInflater inflater = activity.getLayoutInflater(); 
LinearLayout listFooterView = (LinearLayout)inflater.inflate(
      R.layout.footer_layout, null); 

list.addFooterView(listFooterView); 


LinearLayout listHeaderView = (LinearLayout)inflater.inflate(
       R.layout.header_layout, null); 

    list.addHeaderView(listHeaderView); 
+0

感謝您的建議,它非常有幫助。 Iam能夠查看標題文本視圖,但無法查看「section_list_view」,「attachment_list_view」的所有列表項,它們只顯示一個項目。 – 2013-03-26 11:44:07

+0

您需要完全移除滾動視圖,只需使用列表視圖以及頁腳和頁眉,並確保爲兩個單獨的列表視圖提供一些高度 – 2013-03-26 11:48:03

相關問題