0

I use a vertical ScrollView to carry ViewPager and Gridview. ViewPager's position is above the Gridview,and Gridview is use "expand all" to keep it behaviors well inside scrollview.

But. After I use adapter to fill content to these two view. The position is always scroll to Gridview's position at first.User need to scroll it up to see Viewpager themself.

I want its position can at the first viewpager, not the gridview.

Could you give me some suggestions.

Thanks.

The following is my layout file.

        <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>
曾建堂
  • 3
  • 3

1 Answers1

0

Further reading has revealed that there are issues with scrolling components inside scrolling components.

One solution is to 'disable' the vertical scrolling of the ScrollView on the area of the contained scrollable component, in my case a ViewPager.

The code for this solution is detailed here(HorizontalScrollView within ScrollView Touch Handling) (and its simply brilliant!)

Community
  • 1
  • 1
Laxmeena
  • 780
  • 2
  • 7
  • 28