2013-04-30 126 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