按钮栏不会粘在屏幕的底部

时间:2011-04-21 07:25:44

标签: android xml

我正在尝试将我创建的按钮栏放在每个屏幕的底部。我成功完成了第一个屏幕相当容易。

现在我试图把它放在其他屏幕上,但似乎它不能粘在屏幕的底部。当我查看hiearchyviewer时,看起来像包裹了我的布局和按钮栏的RelativeLayout,虽然没有填满整个屏幕,但它的高度设置为填充父级。

任何人都可以通过指出我哪里出错来帮助我吗?

这是我使用的XML:

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

这是我实现的结果和我想要的结果

enter image description here enter image description here

3 个答案:

答案 0 :(得分:6)

如果您希望按钮栏始终显示在屏幕底部而不是滚动内容,则可能需要切换RelativeLayoutScrollView标记,并将按钮栏移至成为您RelativeLayout的第一个孩子,ScrollView成为第二个孩子:

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

这样你就能达到你想要的效果:

portraitlandscape

按钮栏将始终位于屏幕底部。

通过滚动内容,您将能够看到它的最后一点,它不会隐藏在按钮栏后面:

landscape 2

答案 1 :(得分:2)

我仍然建议不要使用ScrollView这里是一个如何在底部显示ButtonBar的例子

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

这就是最强大的解决方案。

如果您觉得有用,请不要忘记将其标记为答案。

答案 2 :(得分:0)

  

请采用一个主线性布局   滚动视图上方和结束后   滚动视图请设置您的底部   酒吧..

这也是我的建议。 LinearLayout是主视图。 在其中

  • 另一个LinearLayout(layout_height = 0dp和layout_weight = 1) * ll_container *
  • 和你tabbar

* ll_container * 地方

  • 带有tablelayout的scrollview(layout_height = 0dp和layout_weight = 1)
  • 和按钮

可能需要解释。使用layout_height = 0dp和layout_weight = 1,您可以在放置标签栏后放置整个空闲位置,然后放置按钮

<强> UPD

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <LinearLayout android:layout_width="fill_parent" 
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">
        <ScrollView android:layout_width="fill_parent"
            android:layout_height="0dp" 
            android:layout_weight="1">
            <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>
            </TableLayout>
        </ScrollView>
        <Button android:text="@string/VindJobButton" android:id="@+id/btnFindJob"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_marginTop="10dip" />
    </LinearLayout>
    <stage.accent.Toolbar android:layout_width="fill_parent"
        android:layout_height="70dip" android:layout_alignParentBottom="true"
        android:layout_below="@+id/table" />
</LinearLayout>
相关问题