Search code examples
androidandroid-layoutandroid-scrollviewandroid-layout-weight

Android UI difficulties


My layout was perfect until I decided to add a scrollview.

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
    <ScrollView android:id="@+id/scrollView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" >
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/linearLayout1">
            <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tableLayout1"/>
        </LinearLayout>
    </ScrollView>
    <Button android:layout_width="match_parent" android:id="@+id/button1" android:text="Start" android:layout_height="50dip" android:onClick="getOutput"></Button>
</TableLayout>

I would like the button to stay at the bottom of the screen, I would actually like the scrollview to take up the entire screen. With just the inner table layout it works fine. In the Graphical Layout preview it looks how I want it, but not when I run it.

I would like the scrollview to take up the whole screen except the button, which I'd like to be at the bottom.


Solution

  • this should work

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" android:layout_height="fill_parent" 
        android:orientation="vertical">
        <ScrollView  android:layout_width="fill_parent" android:layout_height="0dip" 
            android:layout_weight="1.0">
            <LinearLayout android:layout_width="fill_parent" 
                android:layout_height="fill_parent" android:orientation="vertical" 
                android:id="@+id/linearLayout1"> 
                <TableLayout android:layout_width="fill_parent" 
                    android:layout_height="fill_parent" 
                    android:id="@+id/tableLayout1"/> 
            </LinearLayout>
        </ScrollView>
        <Button android:layout_width="fill_parent" android:layout_height="wrap_content" 
            android:text="Bottom Button"/>
    </LinearLayout>