My goal is simple : have a 16/9 ratio image in an imageView. I use a png image which dimensions are 16x9. 2 possibilities for my app :
- portrait : width fixed, has to scale height
- landscape : height fixed, has to scale width
The first one works fine with this layout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/welcomeRootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/welcomePilotingFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@null"
android:scaleType="fitXY"
android:src="@drawable/black_16_9e" />
</FrameLayout>
<!-- Other stuff that aren't relevant -->
</RelativeLayout>
This gives me what i want : my red cornered image is resized
Now the fun part begins : landscape: Here's my layout (symetric off portrait) :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/welcomeLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2" >
<FrameLayout
android:id="@+id/welcomePilotingFrame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ff00ff00" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:contentDescription="@null"
android:scaleType="fitXY"
android:src="@drawable/black_16_9e_border" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/welcomePilotingFrame" />
</RelativeLayout>
<!-- Other stuff that aren't relevant -->
</LinearLayout>
And now, the imageView understands it has to be all its parent high, but does't resize its width and so doesn't keep my 16/9 ratio !
Am I missing something ?