標籤:
轉:http://my.oschina.net/cjk035/blog/127445
最近在做一個項目,上面是一個LinearLayout布局,下面是一個百度地圖的MapView控制項,MapView控制項的高度比較大,導致整個頁面的的內容就超出了螢幕的顯示地區,於是就在外面套了個scrollview,但新問題出現了,每次進入頁面時,由於地圖的載入導致scrollview總是自動滾動到了最底部,上面的LinearLayout地區只顯示了下面的一部分,為瞭解決這個問題我用了scrollview.Fling(0)、scrollview.scrollTo(0,0);但都不管用,沒想到看似簡單的問題卻變得如此地緊手,鼓搗了好久才找到最好的解決辦法:
重寫scrollview中的如下方法,並將其傳回值設為0即可。
@Override
protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
return 0;
}
轉:http://blog.csdn.net/icyfox_bupt/article/details/15026299
問題:
最近在寫一個程式介面,有一個scrollVIew,其中有一段內容是需要線上載入的。
當內容載入完成後,ScrollView中內容的長度會發生改變,這時ScrollView會自動下滾,如所示:
滾動的那一下體驗特別不好,所以要防止這種情況。即不論Scrollview中內容如何,都要保持在最上。
解決辦法:
先簡單寫一下我的xml檔案的結構:
[html] view plain copy
- <ScrollView
- android:id="@+id/scrollView1"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/linearLayout2"
- android:background="@drawable/repeat_bg"
- android:paddingBottom="5dp" >
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:paddingLeft="10dp"
- android:paddingRight="10dp"
- android:focusable="true"
- android:focusableInTouchMode="true"
- android:paddingTop="15dp" >
- <!-- 上面這兩行是控制scrollview
- android:focusable="true"
- android:focusableInTouchMode="true"
- 不自動的關鍵! !-->
-
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
-
- <ListView
- android:id="@+id/lv_gc"
- android:layout_marginTop="5dp"
- android:layout_width="match_parent"
- android:layout_height="20dp"
- android:background="#aaffffff"
- android:divider="#666"
- android:scrollbars="none|vertical" >
-
- </ListView>
-
- </LinearLayout>
- </LinearLayout>
- </ScrollView>
如上面代碼,我的ScrollView中第一個內容是LinearLayout,下面有一個LinearLayout包裹著的ListView.ListView是長度可變的。
將LinearLayout中加入代碼:
[html] view plain copy
- android:focusable="true"
- android:focusableInTouchMode="true"
問題即可解決,歡迎大家交流。
解決Android中,禁止ScrollView內的控制項改變之後自動滾動