If the top-level layout is ConstraintLayout
, you can put all the views of each section into a group. Setting the visibility of a group changes the visibility of all of its member. See Group
.
This class controls the visibility of a set of referenced widgets. Widgets are referenced by being added to a comma separated list of ids, e.g:
<android.support.constraint.Group
android:id="@+id/group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
app:constraint_referenced_ids="button4,button9" />
If the top-level layout is not ConstraintLayout
then you have a couple of options.
Set the visibility of each section member individually (trying to avoid this, but it is an option). You could set up your own internal group references to make it easier.
Wrap each section in another ViewGroup
such as FrameLayout
. Setting the visibility of a ViewGroup
parent affects the visibility of all of its children.
-- section 1 --
FrameLayout
LinearLayout
ImageView
TextView
/LinearLayout
ViewPager
View
-- section 2 --
FrameLayout
LinearLayout
ImageView
TextView
/LinearLayout
ViewPager
View
-- section 3 --
FrameLayout
LinearLayout
ImageView
TextView
/LinearLayout
ViewPager
View
Of course, the ViewGroup
could be LinearLayout
, RelativeLayout
, etc. - whatever makes sense. FrameLayout
is used as an example.