2011-04-21 12 views
7

Estoy tratando de poner la barra de botones que he creado en la parte inferior de cada pantalla. Logré la primera pantalla bastante fácil.La barra de botones no se pegará a la parte inferior de la pantalla

Ahora he intentado ponerle otras pantallas, pero parece que no se puede pegar en la parte inferior de la pantalla. Cuando miro en el hiearchyviewer, parece que el RelativeLayout que está envuelto alrededor de mi diseño y la barra de botones, no está llenando toda la pantalla, sin embargo, su altura está configurada para llenar el elemento principal.

¿Alguien me puede ayudar señalando dónde me estoy equivocando?

Este es el código XML que utilizo:

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

Este es el resultado que he logrado y el resultado que desea obtener

enter image description hereenter image description here

Respuesta

6

En caso de que usted quiere que su barra de botones para estar siempre visible en la parte inferior de la pantalla y se desplaza con el contenido, es posible que desee cambiar sus RelativeLayout y ScrollView etiquetas, y mover su barra de botones para ser el primer hijo de su RelativeLayout , el ScrollView a ser el segundo:

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

de esta manera usted será capaz de lograr lo que quiere:

portrait y landscape

La barra de botones estará siempre en la parte inferior de la pantalla.

Y desplazándose hacia el contenido, podrás ver la última parte de ella también, no se oculta detrás de la barra de botones:

landscape 2

+0

Tengo una pregunta, sin embargo. ¿Qué pasa si mi contenido es más grande que la pantalla. Implementé 'ScrollView', por lo que el desplazamiento no será un problema. Pero el último bit de la pantalla, por ejemplo, un botón de envío, estará oculto después de la barra. ¿Cómo resuelves eso? ? – Hannelore

+0

el ejemplo anterior hace que la barra de botones esté siempre visible (no se desplazará con el contenido). ¿O no le entiendo bien, y el botón de enviar no está en la barra de botones? – rekaszeru

+0

Sí, quiero que se repare la barra de botones como mostraste arriba y luego hay un botón, por ejemplo, que está en la parte inferior de la pantalla de contenido. Luego está escondido detrás de la barra de botones. – Hannelore

0

Por favor, tome una diseño lineal principal arriba vista de desplazamiento y después de terminar vista de desplazamiento configure su parte inferior bar ..

Sería también mi suggetion. LinearLayout es la vista principal. Dentro de ella

  • Otra LinearLayout (layout_height = 0DP y layout_weight = 1) * ll_container *
  • y TabBar

Dentro * ll_container * lugar

  • una vista de desplazamiento (layout_height = 0dp y layout_weight = 1) con tablelayout
  • y el botón

Probablemente la explicación. Con layout_height = 0DP y layout_weight = 1 le da a sus diseños de todo el lugar libre que queda después de realizar su barra de pestañas y luego después de colocar su botón

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

Con las instrucciones de @Chirag I' he logrado hacerlo con un diseño relativo y sin los pesos. ¿Hace alguna diferencia? Me gustaría hacerlo de la manera correcta. – Hannelore

+0

Creo que puedes usar ambas soluciones. Y leí tu pregunta de nuevo. Y entendí que solo quería que la barra de botones debería estar siempre visible. Y no me gustan los diseños relativamente relativos ... simplemente tuve demasiados problemas con ellos – Tima

2

Todavía sugiere no uso ScrollView aquí es una ejemplo de cómo se puede mostrar el ButtonBar en la parte inferior

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

que es todo esto es la solución más robusta.

Si lo encuentra útil, no olvide marcarlo como respuesta.

+0

¿Por qué no usaría ScrollViews? Si mi contenido es más grande (y en algunas pantallas lo es, Android no lo hace desplazarse por sí mismo. – Hannelore

+0

puede agregar un ListView en lugar de comentar o scrollview en ese –

Cuestiones relacionadas