Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invisible components still take up space

Tags:

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>
like image 504
Moko Avatar asked Sep 10 '13 00:09

Moko


2 Answers

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)
like image 184
CommonsWare Avatar answered Sep 20 '22 03:09

CommonsWare


In the java code

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
like image 32
Amirouche Zeggagh Avatar answered Sep 20 '22 03:09

Amirouche Zeggagh