Los componentes invisibles siguen ocupando espacio

So, I have this one activity that looks like this:

http://i.imgur.com/UzexgEA.jpg

As you can see, it has a button, a list and a button.

If certain conditions are met, I want to hide both buttons just show the list, but as you can see in the next image, the buttons are still taking up space:

http://i.imgur.com/OyLIfSk.jpg

So my question, what can I do to enlarge the list to take that space out?

Here is my layout for the buttons and the list:

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

    <Button
        android:id="@+id/findSelected"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="registrarAsistencia"
        android:text="Registrar Asistencia" />

    <ListView
        android:id="@+id/listaAlumnos"
        android:layout_width="fill_parent"
        android:layout_height="376dp"
        android:layout_weight="2.29" />

    <Button
        android:id="@+id/btnChecarBoxes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="seleccionarTodosNinguno"
        android:text="Seleccionar / Deseleccionar todo" />
</LinearLayout>

And here it is the layout for the list's contents:

<?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="match_parent"
    android:orientation="vertical" >

  <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:orientation="vertical" >

      <TextView
          android:id="@+id/rowTextView"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:padding="10dp"
          android:textSize="16sp" 
          android:textStyle="bold"/>

      <TextView
          android:id="@+id/rowTextView2"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:padding="10dp"
          android:textSize="16sp" 
          android:textStyle="italic"/>

  </LinearLayout>

  <CheckBox
      android:id="@+id/CheckBox01"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_alignParentRight="true"
      android:layout_centerVertical="true"
      android:focusable="false"
      android:padding="10dp" />
</RelativeLayout>

preguntado el 10 de septiembre de 13 a las 01:09

4 Respuestas

Do not make the buttons View.INVISIBLE. Make the buttons View.GONE. There are three visibility states:

  • visible (normal)
  • invisible (pixels not drawn, but still takes up space)
  • gone (not included in rendering)

Respondido el 10 de Septiembre de 13 a las 01:09

This worked like a charm. Thank you very much for the fast answer! - Moko

en el codigo java

yourView.setVisibility(View.GONE);

and in the XML code

android:visibility="gone"

Thier are 3 state

  1. visible: normal
  2. invisible : takes space and invisible
  3. gone : no space and no visibility

Respondido 25 Abr '18, 08:04

Utilice las

android:layout_height="0dp"
android:layout_weight="1"

In addition to @CommonsWare's answer

You should use a layout that fits well in all screen sizes. If you give you layout a fixed height like android:layout_height="376dp" it will look good only on the device (or emulator) you're testing on. What you have to do is to make sure that your listview takes up all (and only) the space left by your buttons.

Mira este pequeño artículo y este https://www.youtube.com/watch?v=xB-eutXNUMXJtA&feature=youtu.be to better understand layout weights.

contestado el 23 de mayo de 17 a las 12:05

Im really a beginner with Android, so, mind explaining why 0dp and 1 instead of match_parent and/or wrap_content?. Thanks in advance. - Moko

@Moko I've just updated my answer with more information. I hope it helps. - Androiderson

Got it, will take a look at those. Thanks for the answer! - Moko

for hiding your widget

   yourEditText.setVisibility(View.GONE)

for visbility of your widget

   yourEditText.setVisibility(View.VISIBLE)

Respondido 22 Jul 17, 08:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.