I'm trying to add a simple ViewSwitcher with two ImageViews as children. But no matter what I try, the second child remains invisible. In the XML layout preview in Android Studio it looks like the second child has a size 0x0 pixels. The first child shows up just fine. What's the problem here?
<ViewSwitcher
android:id="@+id/viewSwitcher"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/view1"
android:scaleType="fitXY"
android:src="@drawable/view_1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/view2"
android:scaleType="fitXY"
android:src="@drawable/view_2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</ViewSwitcher>
I'm switching beween the two views simply using gradientViewSwitcher.showNext()
.
Try use a
LinearLayout
andwrap_conent
like this: