Is there an easy way to switch between the displayed view in a ViewSwitcher in the Android Studio preview, or is the only way to swap out the XML for the sub-views one at a time?
Unfortunately, there are no XML attributes or any option on Android Studio which can help you to define the displayed view.
A similar question for the ViewFlipper
was asked here (they both are direct subclasses of ViewAnimator
).
However, if and only if your views are large as the screen, you could use the include
tag, for example:
<ViewSwitcher
android:id="@+id/myViewSwitcher"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/first_view">
</include>
<include
layout="@layout/second_view">
</include>
</ViewSwitcher>
Then you can see your layouts in a separate XML file.