Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Buttonbar won't stick to bottom of screen

Tags:

android

xml

I'm trying to put the buttonbar I've created on the bottom of each screen. I've succeeded for the first screen fairly easy.

Now I've tried to put it other screens, but it seems that it can't stick to the bottom of the screen. When I look in the hiearchyviewer, it looks like the RelativeLayout that's wrapped araound my layout and buttonbar, isn't filling the whole screen, though, its height is set to fill parent.

Can anyone help me by pointing out where I'm going wrong?

This is the XML I use:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical">
    <TableLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:padding="5pt" android:id="@+id/table"
        android:stretchColumns="1">
        <TableRow>
            <TextView android:text="@string/Arbeiderbediende"
                android:id="@+id/txtArbeiderBediende" android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </TableRow>

        <TableRow android:gravity="center">
            <RadioGroup android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:orientation="horizontal"
                android:id="@+id/group1">

                <RadioButton style="@style/RadioButton"
                    android:layout_width="wrap_content" android:id="@+id/rbArbeider"
                    android:text="@string/Arbeider" android:layout_height="wrap_content"
                    android:paddingLeft="18pt" />

                <RadioButton style="@style/RadioButton"
                    android:layout_width="wrap_content" android:id="@+id/rbBediende"
                    android:text="@string/Bediende" android:layout_height="wrap_content"
                    android:layout_marginLeft="20pt" android:paddingLeft="18pt" />
            </RadioGroup>
        </TableRow>

        <TableRow android:gravity="center" android:paddingTop="5dip">
            <TextView android:text="@string/OverzichtFuncties"
                android:id="@+id/txtFuncties" android:layout_width="0dip"
                android:layout_weight="1" android:layout_height="wrap_content" />

            <Spinner android:layout_height="wrap_content" style="Spinner"
                android:layout_width="0dip" android:layout_weight="2"
                android:id="@+id/cmbFuncties" />
        </TableRow>

        <TableRow android:gravity="center" android:paddingTop="5dip">
            <TextView android:text="@string/Regio" android:id="@+id/txtRegio"
                android:layout_width="0dip" android:layout_weight="1"
                android:layout_height="wrap_content" />

            <Spinner android:layout_height="wrap_content"
                android:layout_width="0dip" android:layout_weight="2" android:id="@+id/cmbRegio" />
        </TableRow>

        <TableRow android:gravity="center" android:paddingTop="5dip">
            <TextView android:text="@string/Opleiding" android:id="@+id/txtOpleidingsniveau"
                android:layout_width="0dip" android:layout_weight="1"
                android:layout_height="wrap_content" />

            <Spinner android:layout_height="wrap_content"
                android:layout_width="0dip" android:layout_weight="2"
                android:id="@+id/cmbOpleidingsniveau" />
        </TableRow>

        <Button android:text="@string/VindJobButton" android:id="@+id/btnFindJob"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_marginTop="10dip" />


    </TableLayout>

    <stage.accent.Toolbar android:layout_width="fill_parent"
        android:layout_height="70dip" android:layout_alignParentBottom="true"
        android:layout_below="@+id/table" />
</RelativeLayout>

This is the result I achieved and the result I want to get

enter image description hereenter image description here

like image 595
Hannelore Avatar asked Apr 21 '11 07:04

Hannelore


2 Answers

In case you want your buttonbar to be always visible at the bottom of the screen and not scroll with the content, you might want to switch your RelativeLayout and ScrollView tags, and move your buttonbar to be the first child of your RelativeLayout, the ScrollView to be the second:

<?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" android:orientation="vertical">
    <stage.accent.Toolbar android:id="id/buttonBar" android:layout_width="fill_parent"
        android:layout_height="70dip" android:layout_alignParentBottom="true" />
    <ScrollView android:layout_above="@+id/buttonBar"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
        <TableLayout android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:padding="5pt" android:id="@+id/table"
            android:stretchColumns="1">
            <TableRow>
                <TextView android:text="@string/Arbeiderbediende"
                    android:id="@+id/txtArbeiderBediende" android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </TableRow>
            <TableRow android:gravity="center">
                <RadioGroup android:layout_width="fill_parent"
                    android:layout_height="wrap_content" android:orientation="horizontal"
                    android:id="@+id/group1">

                    <RadioButton style="@style/RadioButton"
                        android:layout_width="wrap_content" android:id="@+id/rbArbeider"
                        android:text="@string/Arbeider" android:layout_height="wrap_content"
                        android:paddingLeft="18pt" />

                    <RadioButton style="@style/RadioButton"
                        android:layout_width="wrap_content" android:id="@+id/rbBediende"
                        android:text="@string/Bediende" android:layout_height="wrap_content"
                        android:layout_marginLeft="20pt" android:paddingLeft="18pt" />
                </RadioGroup>
            </TableRow>
            <TableRow android:gravity="center" android:paddingTop="5dip">
                <TextView android:text="@string/OverzichtFuncties"
                    android:id="@+id/txtFuncties" android:layout_width="0dip"
                    android:layout_weight="1" android:layout_height="wrap_content" />

                <Spinner android:layout_height="wrap_content" style="Spinner"
                    android:layout_width="0dip" android:layout_weight="2"
                    android:id="@+id/cmbFuncties" />
            </TableRow>
            <TableRow android:gravity="center" android:paddingTop="5dip">
                <TextView android:text="@string/Regio" android:id="@+id/txtRegio"
                    android:layout_width="0dip" android:layout_weight="1"
                    android:layout_height="wrap_content" />

                <Spinner android:layout_height="wrap_content"
                    android:layout_width="0dip" android:layout_weight="2" android:id="@+id/cmbRegio" />
            </TableRow>
            <TableRow android:gravity="center" android:paddingTop="5dip">
                <TextView android:text="@string/Opleiding" android:id="@+id/txtOpleidingsniveau"
                    android:layout_width="0dip" android:layout_weight="1"
                    android:layout_height="wrap_content" />

                <Spinner android:layout_height="wrap_content"
                    android:layout_width="0dip" android:layout_weight="2"
                    android:id="@+id/cmbOpleidingsniveau" />
            </TableRow>
            <Button android:text="@string/VindJobButton" android:id="@+id/btnFindJob"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:layout_marginTop="10dip" />
        </TableLayout>
    </ScrollView>
</RelativeLayout>

This way you'll be able to achieve what you want:

portrait and landscape

The button bar will be always at the bottom of your screen.

And by scrolling the content, you'll be able to see the last bit of it too, it won't be hidden behind the buttonbar:

landscape 2

like image 110
rekaszeru Avatar answered Oct 07 '22 07:10

rekaszeru


I still suggests dont use ScrollView here is an example how you can show the ButtonBar at the bottom

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/headerlayout" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        >

        <Button android:id="@+id/amap_back_btn" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true" android:text="Back">
        </Button>
        <TextView  android:id="@+id/amap_txt"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="" android:layout_centerVertical="true"
            android:layout_centerHorizontal="true">
        </TextView>
        <ImageButton android:id="@+id/amap_action_btn"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:src="@drawable/icon_menu_action"
            android:layout_alignParentTop="true" android:layout_alignParentRight="true">
        </ImageButton>
    </RelativeLayout>

    //What ever widgets you wants to add

    <LinearLayout 
    android:id="@+id/bottomlayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:orientation="horizontal"

    >

        <ImageButton android:id="@+id/map_refresh_btn"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:src="@drawable/icon_refresh" 
            android:gravity="center"
            >
        </ImageButton>
        <Button android:id="@+id/map_log_btn" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Log"
            android:gravity="center">
        </Button>
        <Button android:id="@+id/map_map_btn" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Map"
            android:gravity="center"
            >
        </Button>
    </LinearLayout>

</RelativeLayout>

that is all this is the most robust solution.

If you find it useful dont forget to mark it as an answer.

like image 35
Anup Rojekar Avatar answered Oct 07 '22 08:10

Anup Rojekar