如何让Scroll View在其中包含可扩展列表视图时工作?

时间:2014-02-27 13:40:47

标签: android scrollview expandablelistview

        I am having Expandable List View inside a scroll view.Here is my layout :

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

          <RelativeLayout 
                    android:id="@+id/parentLayout"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent">

                    <RelativeLayout
                        android:id="@+id/first_layout"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:paddingTop="5dp" >

                        <com.tfe.view.GabrielGridView
                            android:id="@+id/sample_grid"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="15dp"
                            android:columnWidth="20dp"
                            android:horizontalSpacing="5dp"
                            android:numColumns="auto_fit"
                            android:stretchMode="columnWidth"
                            android:verticalSpacing="5dp" >

                        </com.tfe.view.GabrielGridView>

                    </RelativeLayout>

                    <RelativeLayout

                        android:id="@+id/secondLayout"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/first_layout"
                        android:paddingBottom="10dp" >


                            <TextView
                                android:id="@+id/textView1"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginRight="24dp" />

                        </RelativeLayout>




                    <RelativeLayout
                        android:id="@+id/third_Layout"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:layout_below="@id/second_Layout" >

                        <View
                            android:id="@+id/divider"
                            android:layout_width="fill_parent"
                            android:layout_height="3dp"/>

                        <ExpandableListView
                            android:id="@+id/expandableListViewLayout"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:cacheColorHint="#00000000"
                            android:layout_margin="10dp"
                            android:layout_marginTop="20dp"
                            android:footerDividersEnabled="false"
                            android:groupIndicator="@null" />

                    </RelativeLayout>

                </RelativeLayout>

    </ScrollView>

    Here I am using a **custom GridView** called Gabriel GridView. **My scroll view doesn't work because of my List View inside it. How can I make it work?**

1 个答案:

答案 0 :(得分:1)

在另一个可滚动视图中使用可滚动视图不是一个好选择。但是,如果您想要使用嵌套的可滚​​动视图而不管警告。然后在自定义网格视图 NonScrollableGabrielGridView 上创建自己的自定义 NonScrollableExpandableListView 和包装器。然后覆盖两个组件上的onMeasure()方法,如:

@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // Do not use the highest two bits of Integer.MAX_VALUE because they are
        // reserved for the MeasureSpec mode
        int heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightSpec);
        getLayoutParams().height = getMeasuredHeight();
    }

再次,这是一个糟糕的选择