2011-06-08 92 views
0

下午好,彈力滾動型垂直

我對用戶的屏幕上正在逐漸生成的列表,(現在的名單是坐在一個滾動視圖,但可能不會是最後的歸宿。)以上scrollview是幾個按鈕,scrollview下面是幾個按鈕。滾動查看佔據整個屏幕的中間。

現在,當列表生成時,它將位於滾動視圖下的按鈕下。不過,我希望它停在頂端。同時尋找它始終顯示最後一行,而不是新的信息開始消失在底部。

我知道這可能是令人困惑的,所以如果您有任何問題,請讓我知道。

現在XML看起來有點像這樣,它也按照這個順序排列在屏幕上。

<Button 
    android:text="Ok" 
    android:id="@+id/buttonOk" 
    android:layout_height="wrap_content" 
    android:layout_width="75sp" 
    android:layout_below="@+id/textHoleNumber" 
    android:layout_alignParentRight="true"></Button> 

<ScrollView <-- ***would like this to line up under the OK button*** 
    android:layout_height="wrap_content" 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_below="@+id/buttonMinus"> 

    <TextView 
     android:id="@+id/textScoreCard" 
     android:layout_height="wrap_content" 
     android:text="Score card info goes here" 
     android:textSize="20sp" 
     android:layout_width="fill_parent"></TextView> 

</ScrollView> <-- ***would like this to stay above linear layout*** 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:id="@+id/linearLayout1" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true"> 

    <Button 
     android:layout_height="wrap_content" 
     android:layout_width="0dip" 
     android:layout_weight="1" 
     android:id="@+id/buttonSave" 
     android:text="Save"></Button> 

    <Button 
     android:id="@+id/buttonReset" 
     android:layout_height="wrap_content" 
     android:layout_width="0dip" 
     android:layout_weight="1" 
     android:layout_toRightOf="@+id/buttonSave" 
     android:layout_alignTop="@+id/buttonSave" 
     android:layout_alignBottom="@+id/buttonSave" 
     android:text="Reset"></Button> 

</LinearLayout> 

回答

2

如果你在說些什麼,我認爲你是,嘗試將邊緣的滾動型的底部,並且陰性切緣的線性佈局的頂部。例如:

<ScrollView android:id="@+id/scrollView1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_marginBottom="60sp"> 
     <LinearLayout android:id="@+id/linearLayout1" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent"> 
     </LinearLayout> 
</ScrollView> 

<LinearLayout android:id="@+id/linearLayout2" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="-60sp"> 
</LinearLayout> 

至於何時加入一個新的項目滾動到滾動視圖的底部,看看How to scroll to bottom in a ScrollView on activity startup

注意:這是假設你有你的ScrollView和LinearLayout在它下面,它包含在一個垂直的LinearLayout中。

+0

謝謝!這就像一個魅力。我已經試過保證金和傳遞的滾動視圖,但我不認爲包括-60sp在scrollview下面的linearlayout。 – Rob 2011-06-08 00:51:29

3

總是在線性佈局內使用Scrollview,並給android:layout_weight =「1」。試試下面的例子中,將工作..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:background="@null"> 

<LinearLayout android:id ="@+id/layout_above_scrollview" android:orientation="vertical" 
android:layout_width="fill_parent" android:layout_height="fill_parent"> 

<ScrollView android:id="@id/android:list" android:layout_width="fill_parent" 
android:layout_height="wrap_content" android:layout_weight="1"> 

<LinearLayout android:id ="@+id/layout_above_scrollview" android:orientation="vertical" 
android:layout_width="fill_parent" android:layout_height="fill_parent"> 

// Your components........ 

</LinearLayout> 

</ScrollView> 

<LinearLayout android:id="@+id/add_app_done_layout" android:layout_height="wrap_content" 
    android:layout_width="wrap_content" android:layout_marginTop="5dp"  
      android:layout_marginLeft="50dp" 
    android:orientation="horizontal" android:layout_alignParentBottom="true"> 

<Button android:id="@+id/add_app_done" android:text="Done" 
    android:layout_width="100dp" 
    android:textStyle="bold" android:layout_height="wrap_content" /> 

<Button android:id="@+id/add_app_revert" android:text="Revert" 
    android:layout_width="100dp" android:layout_marginLeft="5dp" 
    android:textStyle="bold" android:layout_height="wrap_content" /> 

</LinearLayout> 


</LinearLayout> 

+0

+1 - 謝謝!!!! – timonvlad 2013-09-25 10:47:33