0

Good Afternoon,

I have a list being generated gradually on the users screen, (right now the list is sitting in a scrollview but that might not be the final resting place.) Above the scrollview are a few buttons, and below the scrollview are a few buttons. Scrollview takes up whole middle of the screen.

Right now, as the list is generated, it goes under the buttons below the scrollview. I would like it however to stop at the top. Also looking for it to always display the last line, rather than the new information start disappearing at the bottom.

I know this is probably confusing so if you have any questions please let me know.

Right now the XML looks a little something like this, and its layed out in this order on the screen too.

    <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>
Rob
  • 1,162
  • 2
  • 18
  • 43

2 Answers2

3

Always use Scrollview inside linear layout and give android:layout_weight="1". Try following example it will work..

<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>

Pradeep
  • 2,530
  • 26
  • 37
2

If you're talking about what I think you are, try adding a margin to the bottom of the scrollview, and a negative margin to the top of the linear layout. For instance:

<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>

As for scrolling to the bottom of the scrollview when a new item is added, look at How to scroll to bottom in a ScrollView on activity startup.

Note: This is assuming you have your ScrollView and the LinearLayout beneath it all contained in a vertical LinearLayout.

Community
  • 1
  • 1
John Leehey
  • 22,052
  • 8
  • 61
  • 88
  • Thank you! That worked like a charm. I had tried margin and passing on the scrollview, but I did not think to includ a -60sp on the linearlayout below that scrollview. – Rob Jun 08 '11 at 00:51