2011-04-21 86 views
7

我想把我在每个屏幕底部创建的按钮栏。我成功的第一个屏幕相当简单。按钮栏不会粘到屏幕底部

现在我试着把它放在其他屏幕上,但它似乎不能粘到屏幕的底部。当我查看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 hereenter image description here

回答

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

+0

但是,如果我的内容比屏幕大,我实现了'ScrollView',所以滚动不会成为问题,但是屏幕的最后一点,例如提交按钮,会在后面隐藏,你怎么解决这个问题? ? – Hannelore 2011-04-21 08:15:00

+0

上面的示例使按钮栏始终可见(不会滚动显示内容)或者我误解了您,并且提交按钮不在按钮栏中? – rekaszeru 2011-04-21 08:20:29

+0

是的,我希望按钮栏是固定的就像你上面显示的那样,然后有一个按钮,例如,它位于内容屏幕的底部,然后隐藏在按钮栏后面 – Hannelore 2011-04-21 08:23:08

0

请带一个滚动视图和结束后的主要线性布局 滚动视图请设置底部 吧..

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

  • 另外的LinearLayout(layout_height = 0dp和layout_weight = 1)* ll_container *
  • 和你的TabBar

* ll_container *地方

  • 一个滚动视图(layout_height = 0dp和layout_weight = 1)与桌面布局
  • 和按钮

可能是为了解释。随着layout_height = 0dp和layout_weight = 1你给你的布局,将您的TabBar,然后把你的按钮

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> 
+0

随着@Chirag我的指示”我设法用一个相对的布局来做,而且没有权重。它有什么区别?我想以正确的方式做到这一点。 – Hannelore 2011-04-21 07:50:18

+0

我想,你可以使用这两种解决方案。我再次读你的问题。而且我明白你只想要buttonbar应该始终可见。我不喜欢真正的相对布局......我只是有太多的问题与他们 – Tima 2011-04-21 10:03:01

2

我还是建议不要在这里使用滚动型是一个示例如何在底部显示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> 

这就是所有这些都是最稳健的解决方案。

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

+0

为什么不使用ScrollViews?如果我的内容比较大(在某些屏幕上,Android不会自动滚动) – Hannelore 2011-04-21 07:51:45

+0

您可以添加ListView来代替该评论或滚动视图 – 2011-04-21 09:33:06