Hiding / hiding internal layouts in Android

I need to be able to hide / show (in the sense of View.GONE) an entire linear line of the layout in Activity. Is this the best approach just to get a link to the internal layout that is part of a larger relative layout and set visibility on that internal layout? You should also keep the link to the layout so that I can just do innerLayout.setVisibility (View.GONE). If so, what type of link should it be? finale or better just do a search every time I want to hide / show. Be that as it may, the direct link to the layout does not look quite right. On the other hand, I don’t want every element in the layout to go away or put findBy to find it every time I hide / open.

Perhaps adding / removing a layout is better? but then I would need to add the right place in the View hierarchy by placing this logic in the code, also not a good idea.

+3
source share
1 answer

Is yur line layout installed in XML or programmatically?

if it is done in XML:

note that if any views use this view as a link in the layout, such as android: layout_below = "@ + id / this", then this would not be a good idea.

You can use something like this, it will hide all child views and itself, it will not hide, but will completely leave (space is not occupied by it)

Use this as a reference in a class if you want to use it in several ways or in the method that you use.

View layout;

Then in onCreate call this

layout = findViewById(R.id.linearLayout);

:

layout.setVisibility(View.GONE);

layout.setVisibility(8);

layout.setVisibility(View.VISIBLE);

layout.setVisibility(0);
+2

All Articles