2013-04-30 115 views
0

我有一個scrollView,裏面有兩個LinearLayout,但它不起作用,listView不顯示所有的項目,但只有少數。我能怎麼做?帶有LinearLayout的ScrollView不起作用

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

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 



    <LinearLayout 
     android:id="@+id/welcomeView" 
     android:layout_width="250dp" 
     android:layout_height="100dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="30dp" 
     android:gravity="center" 
     android:orientation="horizontal" 
     android:weightSum="100" > 

     <ImageView 
      android:id="@+id/image_User_welcome" 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:layout_weight="70" 
      android:src="@drawable/user" /> 

     <TextView 
      android:id="@+id/private_area_welcome" 
      style="@style/CoopLabel" 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:layout_weight="30" 
      android:text="@string/private_area_welcome" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/layout_list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_below="@+id/welcomeView">  
    <TextView 
     android:id="@+id/private_area_lists" 
     style="@style/CoopLabel" 
     android:layout_width="280dp" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/linearLayout1" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:gravity="center" 
     android:text="@string/private_area_lists" /> 

    <ListView 
     android:id="@+id/privareaList" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="5dp" 
     android:textColor="#000000" > 
    </ListView> 

    <ImageButton 
     android:id="@+id/logoutBtn" 
     android:layout_width="160dp" 
     android:layout_height="35dp" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:padding="0dp" 
     android:scaleType="centerCrop" 
     android:src="@drawable/tasto_logout" 
     /> 

    </LinearLayout> 

    </RelativeLayout> 

    </ScrollView> 
+4

'ListView'它自己是一個可滾動的組件。您不應該在ScrollView中添加ListView。 – MAC 2013-04-30 13:03:43

+0

你的scrollview顯示的所有視圖,請注意它。如果可能的話也顯示截圖... – 2013-04-30 13:03:49

+0

@MAC,但listView是在一個LinearLayout – 2013-04-30 13:05:26

回答

2

不建議使用包含其他滾動條的滾動條 - 佈局包含Scrollview中的ListView。您可以將您的佈局設計爲一個ListView - 您可以添加頁眉和頁腳視圖(welcomeView,logoutBtn等)到列表視圖的頂部和底部 - 請參閱方法ListView.addHeaderView和addFooterView) - 滾動將被管理通過ListView,

或者您可以用簡單的LinearLayout替換原始佈局中的listview,並逐行手動填充它(不要忘記將點擊偵聽器分配給行等。) - 滾動將由ScrollView管理。

要查找有關此問題的更多信息,請嘗試Google「android listview inside scrollview」,我相信它會幫助你。 :-)

+0

listView動態變化,我不能手動填充它,這裏有其他方法嗎? – 2013-04-30 13:24:15

+0

如果您需要使用listview,則可以使用第一個選項 - 帶有頁眉和頁腳視圖的listview。可能它更有效率,但我認爲你也可以使用第二個選項 - 你可以從LinearLayout中移除所有視圖,並在需要時用新項目「重新填充」它,不是嗎? :-) – 2013-04-30 13:26:30

+0

看看https://github.com/commonsguy/cwac-merge MergeAdapter。 – Wenger 2013-04-30 16:24:12