2011-04-21 82 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