I have some ImageViews inside a ViewFlipper. I want to respect the aspect ratio of the images, so the layout won’t use all the screen. I have set up a simple “slide” animation, but the ViewFlipper will always be a bit bigger than the images inside. This makes an undesired black space appear between two sliding images. I can’t make the ViewFlipper wrap around the ImageViews correctly.
Everything is inside a FrameLayout, so there I can have a floating button there too. This is the main layout XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="centerInside"
>
<ViewFlipper
android:id="@+id/flipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="centerInside"
>
<ImageView
android:id="@+id/page1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="@drawable/bg0"
/>
<ImageView
android:id="@+id/page2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="@drawable/bg1"
/>
</ViewFlipper>
<ImageButton
android:id="@+id/menuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:src="@drawable/btn_menu"
android:background="@null"
/>
</FrameLayout>
If I set the scaleType of the ImageViews to “fitXY” the black margin disappears, but the ratio of the images is not respected. I have already tried “fitCenter”, “fillParent” in the ImageViews, and a padding of 0px.
Any help is very much appreciated as I have been struggling with this for hours.
Adding this to the ImageView did it: