Search code examples
androidlayoutscrollscrollviewfooter

Android: How to create a layout similar to Calendar app - create event


I'm trying to create a form very similar to the "Create event" screen of the native Calendar app on Android 2.x Basically it has a fixed header, fixed footer and the middle is (I guess) a ScrollView with different "questions" such as "Event", "From", "To", "Location" etc...

I've tried a few options but I can't find the right layout that doesn't involve calculating the height of the screen

Any help would be very much appreciated!


Solution

  • I use a RelativeLayout:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/status_header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:paddingTop="8px"
        android:paddingBottom="8px"
        android:gravity="center"
        android:textColor="@color/header_foreground"
        android:background="@color/header_background"
        android:text="@string/status_header"/>
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/statuspanel"
        android:layout_above="@+id/status_footer">
    

    Put all your middle bits here, maybe in a TableLayout

    </ScrollView>
    <TableLayout
        android:id="@+id/status_footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:paddingTop="4px"
        android:paddingLeft="2px"
        android:paddingRight="2px"
        android:stretchColumns="*"
        android:textColor="@color/footer_foreground"
        android:background="@color/footer_background">
        <TableRow>
            <Button
                android:id="@+id/status_backbutton"
                android:layout_width="0px"
                android:layout_weight="1"
                android:text="@string/status_backbutton" />
        </TableRow> 
    </TableLayout>
    </RelativeLayout>
    

    You'll have to excuse all my colour bits, but you get the idea. It's using alignParent elements in a RelativeLayout which is key, I think