views:

248

answers:

2

I am trying to set up a scrollview in the middle of the screen, in between a header (tablelayout) and a footer (button within ralativelayout).... My problem is that while the child items (edittext and spinners) stay in the assigned area, the scrollbar extends the entire length of the screen. Any idea what I'm doing wrong? Thanks in advance.

Here is the xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content"  android:stretchColumns="0">

  <TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="@string/title" />
        <EditText android:id="@+id/title" 
          android:layout_height="wrap_content" 
            android:layout_width="wrap_content" android:hint="Montague St."/>
  </TableRow>

  <TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="@string/body" />
        <EditText android:id="@+id/body" android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:scrollbars="vertical" android:hint="44"/>
        </TableRow>


    </TableLayout><TableRow android:id="@+id/TableRow03" android:layout_height="wrap_content" android:layout_width="wrap_content"><TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="House Number                 "></TextView>
<TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Status         "></TextView>
<TextView android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="# of Visits"></TextView>
</TableRow>

<ScrollView android:id="@+id/ScrollView01" android:isScrollContainer="true" android:layout_width="wrap_content" android:clipChildren="true" android:clipToPadding="true" android:layout_height="wrap_content" android:layout_marginBottom="50dip">


<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"><TableLayout android:id="@+id/TableLayout02" android:layout_width="wrap_content" android:layout_height="wrap_content">



<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="House Number   "></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout android:layout_marginTop="-50dip" android:gravity="bottom" android:layout_height="wrap_content" android:layout_width="fill_parent">
<Button android:id="@+id/confirm" 
      android:text="@string/confirm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>     </RelativeLayout>    

</LinearLayout>
A: 

you might want to try setting in your ScrollView:

android:layout_above="@id/The_RelativeLayout_that_has_your_bottom_button"
android:layout_below="@id/The_one_that_should_be_above_the_scroll_view"

Sorry to be vague, but your xml is very very difficult to read with the formatting as it is right now.

But the idea is, in your ScrollView, you can tell it to be between (or above and below) two other objects. You will need to give those two other objects (the RelativeLayout and maybe a TableRow?) id's so that you can reference those id's in the ScrollView.

Aurora
This will not work, it's a LinearLayout and not a RelativeLayout
fedj
Ah so you are right. I'd like someone with editing abilities to fix the xml. :(
Aurora
+1  A: 

You should take a look to android:layout_weight attribute

fedj
Please set question as answered when they are ...
fedj