Layout adjustViewBounds is not wokring

136 Views Asked by At

I want the ImageView keep its aspect ratio with layout_height=match_parent but I don't know why this happen ?

bob

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
           android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:background="@drawable/bob" />
        <TextView
            android:gravity="center"
          android:textAppearance="@style/TextAppearance.AppCompat.Headline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Bob" />
    </LinearLayout>
</LinearLayout>
2

There are 2 best solutions below

0
On

Use for this to set in full image view scaletype=fitxy

5
On
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
           android:layout_width="wrap_content"
            android:layout_height="match_parent"

            android:background="@drawable/bob" />
        <TextView
            android:gravity="center"
          android:textAppearance="@style/TextAppearance.AppCompat.Headline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Bob" />
    </LinearLayout>
</LinearLayout>