2012-07-04 40 views
3

在我的應用程序中,我正在進行一些計算。整個佈局在滾動視圖內。在發生動作後將焦點設置在scrollview的頂部android

結果顯示在最上面。 XML是這樣的:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/back2back" 
    > 


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="526dp" 
    android:background="@drawable/back4" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/nothing" 
     android:layout_width="181dp" 
     android:layout_height="51dp" 
     android:layout_gravity="center" 

     android:textColor="#000000" 
     android:textStyle="bold" /> 

     rest of the xml 
    </LinearLayout> 
</ScrollView> 

所以我按計算按鈕時,屏幕的焦點被設置爲我的頁面的頂部(或在上部的TextView更具體),以便用戶將要能夠看到結果。我在SO搜索,但我還沒有找到類似的東西。

回答

10

如果我明白你的問題,只需撥打:

scrollView.scrollTo(0, 0); 

在你的計算按鈕的OnClickListener。

+0

是的,這就是我的意思。 – ghostrider