How to eliminate the space left by invisible views on the screen?

Asked

Viewed 336 times

2

I am working on an android application and my question is: When the user logs in the application, it checks the permissions of the same.
How can I make this button invisible and organize so as not to be blank the space that this button occupied ?

Below are some buttons I’m using in the Menu class:

  btnDadosCadastrais      = (Botton) findViewById(R.id.dadosCadastrais);
        btnDadosCadastrais.setOnClickListener(this);

        btnDebitosPendentes     = (CardView)findViewById(R.id.debitosPendentes);
        btnDebitosPendentes.setOnClickListener(this);

        btnHistoricoPagementos  = (Botton) findViewById(R.id.HistoricoPagamento);
        btnHistoricoPagementos.setOnClickListener(this);

        btnSolicitarAtendimento = (Botton) findViewById(R.id.solicitarAtendimento);
        btnSolicitarAtendimento.setOnClickListener(this);

        btnHistoricoAtendimento = (Botton) findViewById(R.id.historicoAtendimento);
        btnHistoricoAtendimento.setOnClickListener(this);

        btnGraficosDeUso        = (Botton) findViewById(R.id.graficoDeUso);
        btnGraficosDeUso.setOnClickListener(this);

        btnExtratoDeAutenticacao= (Botton) findViewById(R.id.ExtratoAutenticacao);
        btnExtratoDeAutenticacao.setOnClickListener(this);

2 answers

6


The visibility of a view can have three states:

  • Visible - the view is visible on the screen.
  • Invisible - the view is not visible but takes up space.
  • Gone - the view is not visible and does not take up space.

Visibility is controlled in xml by the attribute android:visibility and in java through the method setVisibility().

For what you want to use the state Gone

java:

button.setVisibility(View.GONE);

xml:

android:visibility="gone"
  • 1

    Thanks for the reply, @Ramaral, I did not have this information that Invisible still occupied the space.

3

Within the class of Activity, use the object containing this button and when enter the condition to become invisible implement:

button.setVisibility(View.GONE);

If you have any conditions to return visibility, use:

button.setVisibility(View.VISIBLE);
  • but how do I get the space the button occupied so they don’t go blank? so that another button goes up to its place.

  • 1

    With View.GONE the layout reorganizes, what you’re saying occurs if you use View.INVISIBLE

  • It worked, thank you.

  • 1

    For nothing! We are there...

Browser other questions tagged

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