繁体   English   中英

内部使用LinearLayout的ScrollView不起作用

[英]ScrollView with LinearLayout inside does not work

我有一个带有两个内部LinearLayout的scrollView但它不起作用,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>  

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM