How to play a layout component up?

Asked

Viewed 82 times

1

Good afternoon I’m making an app for studies, and I’m encountering a small problem is not enough to be a bug, but come on, this is my home screen:

As it is in the print below, I have a relative layout that has 1 note with its edittext and weight with its edittext.

when I click on the + one that is an Imagebutton it enters the setonclicklistnner and visible arrow pro another relative layout that is just below...

inserir a descrição da imagem aqui

In this part that is circled red is another element that is inside a relative layout that has its own id, in that x he arrow Invisible pro note 2, getting as it was in image two...

inserir a descrição da imagem aqui

Now after explaining, my question is how do I make that blank part where is the other relative sum layout ? as if there was nothing there, and the result and the sum stay close to the note 1?

my layout code is this:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:text="Nome da Matéria:"
        android:textSize="16dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text="Name"
        android:ems="10"
        android:id="@+id/editText2" />

</RelativeLayout>

<RelativeLayout
    android:layout_marginTop="10dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:text="Nota 1:"
        android:textSize="18dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView2"


        android:textAllCaps="false" />

    <TextView

        android:text="Peso"
        android:layout_marginLeft="120dp"
        android:textSize="18dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:id="@+id/textView3" />


</RelativeLayout>


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <EditText
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:text=""
        android:ems="10"
        android:id="@+id/editText3"
       />

    <EditText

        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:text=""
        android:ems="10"
        android:id="@+id/editText"
        android:fontFamily="sans-serif"
        android:layout_marginLeft="120dp"
         />

 <ImageButton
     android:layout_width="wrap_content"
     android:background="#fff"
     android:layout_marginLeft="220dp"
     android:src="@drawable/plus_one"
     android:id="@+id/more1"
     android:layout_height="wrap_content" />


</RelativeLayout>


<RelativeLayout
    android:visibility="invisible"
    android:id="@+id/lig1"
    android:layout_marginTop="10dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:text="Nota 2:"
        android:textSize="18dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAllCaps="false" />

    <TextView

        android:text="Peso"
        android:layout_marginLeft="120dp"
        android:textSize="18dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


</RelativeLayout>



<RelativeLayout
    android:visibility="invisible"
    android:id="@+id/lig1.1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <EditText
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:text=""
        android:ems="10"
        android:id="@+id/editText4"
        />

    <EditText

        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:text=""
        android:ems="10"
        android:id="@+id/editText5"
        android:fontFamily="sans-serif"
        android:layout_marginLeft="120dp"
        />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/closerlig1"
            android:background="#fff"
            android:layout_marginLeft="220dp"
            android:src="@drawable/close_box_outline"
            />


</RelativeLayout>


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView4"
        android:textSize="20sp" />

    <Button
        android:text="Somar"
        android:layout_alignParentRight="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/resultado"
        android:textAllCaps="false" />

</RelativeLayout>

1 answer

3


Rogers,

You need to understand the difference Invisible and Gone.

If you use the android:visibility="invisible" the layout will remain there, however invisible, so his space continues.

Now if you use the android:visibility="gone" the layout will remove that part from there, taking out even the white space.

Java example:

id_do_seu_layout.setVisibility(View.GONE);

and to make it appear again in the layout:

id_do_seu_layout.setVisibility(View.VISIBLE);
  • ata thanks I didn’t know, do . Gone the Visible and Invisible I knew vlw help!

  • I’m glad I was able to help you before they locked the question...!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.