[英]Why position allways scroll to gridview's position inside my ScrollView?
我使用垂直的ScrollView來承載ViewPager和Gridview。 ViewPager的位置在Gridview上方,並且Gridview使用“全部展開”以使其在滾動視圖內的行為保持良好。
但。 之后,我使用適配器將內容填充到這兩個視圖中。 該位置始終始終首先滾動到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>
進一步的閱讀顯示,滾動組件內部存在滾動組件問題。
一種解決方案是“禁用”所包含的可滾動組件(在本例中為ViewPager)所在區域的ScrollView的垂直滾動。
此處詳細介紹了此解決方案的代碼( ScrollView Touch Handling中的HorizontalScrollView )(及其出色的功能!)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.