0

我有一个在 LinearLayout 中有两个的滚动视图,但它不起作用,listView 不显示所有项目,而只显示少数项目。我能怎么做?

  <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

1 回答 1

2

不建议使用包含其他可滚动项的可滚动项 - 您的布局在 Scrollview 中包含 ListView。

您可以将布局设计为 ListView - 您可以将页眉和页脚视图(welcomeView、logoutBtn 等)添加到 listview 的顶部和底部 - 请参阅方法 ListView.addHeaderView 和 addFooterView) - 滚动将由 ListView 管理,

或者您可以用简单的 LinearLayout 替换原始布局中的 listview 并逐行手动填充(不要忘记将点击侦听器分配给行等。) - 滚动将由 ScrollView 管理。

要查找有关此问题的更多信息,请尝试 google “android listview inside scrollview”,我相信它会对您有所帮助。:-)

于 2013-04-30T13:20:19.707 回答