ScrollView中的GridView和ListView

时间:2014-04-18 12:18:00

标签: android

我在LinearLayout中创建了gridview和listview。显示的数据是动态的。 gridview填充屏幕高度的80%。而listview只有屏幕高度的20%,其中项目是可滚动的,但由于屏幕高度listview的可用性,一次只显示2项..

现在我想要listview的父级和gridview是可滚动的,但gridview和listview不是这样的,列表视图一次可以显示2个以上的项目。

  

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:orientation="vertical" >


    <include layout="@layout/app_headerview_imageview_textview" />

    <GridView
        android:id="@+id/gridView"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:listSelector="@null"
        android:numColumns="3"
        android:layout_weight="1" >
    </GridView>

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#112F51"
        android:orientation="horizontal"
        android:padding="20dip" >

        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/diagnose_button_selector"
            android:text="Auto Diagnose" 
            android:textColor="#ffffff"
            android:textSize="@dimen/small_text_size"
            android:padding="@dimen/padding_medium"/>

        <View
            android:layout_width="0dip"
            android:layout_height="1dip"
            android:layout_weight=".2" />

        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/diagnose_button_selector"
            android:text="Diagnose Now"
               android:textColor="#ffffff"
            android:textSize="@dimen/small_text_size"
            android:padding="@dimen/padding_medium" />
    </LinearLayout>

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1" >
    </ListView>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#E6E6E6"
    android:orientation="vertical" >

    <include layout="@layout/bottom_action_bar" />
</LinearLayout>

1 个答案:

答案 0 :(得分:1)

  1. scollview应该只有一个直接孩子

  2.   

    你永远不应该使用带有ListView的ScrollView,因为ListView   负责自己的垂直滚动。最重要的是,这样做   击败ListView中的所有重要优化以进行处理   使用大型列表,因为它有效地强制ListView显示   它的整个项目列表,用于填充由提供的无限容器   滚动型。

  3. 如果您希望屏幕上有更多的列表视图,并提供gridview也可滚动的事实,则应对LinearLayout的两个子项使用 weight 属性,以便他们在屏幕上占用了相似的空间