为什么位置总是滚动到我在ScrollView中的gridview位置?

时间:2014-07-09 11:27:08

标签: android gridview position scrollview

我使用垂直ScrollView来携带ViewPager和Gridview。 ViewPager的位置在Gridview之上,Gridview使用"展开全部"在scrollview中保持良好的行为。

但是。之后我使用适配器将内容填充到这两个视图中。该位置始终首先滚动到Gridview的位置。用户需要将其向上滚动以查看Viewpager自己。

我希望它的位置可以在第一个viewpager,而不是gridview。

你能给我一些建议。

感谢。

以下是我的布局文件。

        <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollbarAlwaysDrawVerticalTrack="true" >

        <LinearLayout
            android:id="@+id/linearlayout_dynamicRoot"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <FrameLayout
                android:id="@+id/viewpager_fl"
                android:layout_width="fill_parent"
                android:layout_height="160dp" >



                <myViewPager
                    android:id="@+id/vp"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" />
            </FrameLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="40dp"
                android:background="#B0000000"
                android:gravity="center"
                android:orientation="horizontal" >

                <LinearLayout
                    android:id="@+id/ll_dot_dynamic"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:orientation="horizontal" >

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="0dp" />
                </LinearLayout>

                <TextView
                    android:id="@+id/tv_title"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:ellipsize="end"
                    android:gravity="center_vertical|center_horizontal"
                    android:maxLines="1"
                    android:textColor="#FF7700"
                    android:textSize="20dp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/tv1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="GridView_Header1"
                    android:textColor="#ff7700"
                    android:textSize="20dp"
                    android:visibility="gone" />

                <GridView
                    android:id="@+id/gv1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                     >
                </GridView>



            </LinearLayout>
        </LinearLayout>
    </ScrollView>

1 个答案:

答案 0 :(得分:0)

进一步阅读表明滚动组件内部滚动组件存在问题。

一种解决方案是在所包含的可滚动组件的区域内“禁用”ScrollView的垂直滚动,在我的例子中是ViewPager。

此解决方案的代码详见(HorizontalScrollView within ScrollView Touch Handling)(简直太棒了!)