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

2

I'm working on an android application and my question is: When the user logs into the application, it checks the permissions of the application. How can I make this button invisible and organize to not leave blank the space that this button occupied?

Here are some of the 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);
    
asked by anonymous 24.11.2016 / 18:47

2 answers

5

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 android: visibility attribute. and java using the setVisibility () method.

For what you want, you should use the gone status

Java:

button.setVisibility(View.GONE);

xml:

android:visibility="gone"
    
24.11.2016 / 18:56
3

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

button.setVisibility(View.GONE);

If you have any condition to return to visibility, use:

button.setVisibility(View.VISIBLE);
    
24.11.2016 / 18:53