I am facing with problem button shows outside the screen in RelativeLayout. ImageView doesn't o scale picture to give a button visible place.
What I have:

What I want:

Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center_vertical"  >
<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/str"
        android:textAppearance="@android:style/TextAppearance.Small"
        android:textColor="?android:attr/textColorTertiary"
        android:layout_centerHorizontal="true"
        />
<ru.mw.widget.DrawableImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:adjustViewBounds="true"
        android:layout_centerHorizontal="true"
        android:scaleType="centerCrop"
        />
<Button
        android:id="@+id/processButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/str"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true"
        />
Problem when I change screen orientation: If I use Arun C Thomas's method in landscape mode everything is ok, but in portrait mode I have this (image cropped by left/right edges):
 What is expected:
What is expected:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center_vertical"  >
<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/str"
        android:textColor="?android:attr/textColorTertiary"
        android:textAppearance="@android:style/TextAppearance.Small"
        android:layout_centerHorizontal="true"
        />
<ru.mw.widget.DrawableImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    android:layout_above="@+id/processButton"
     />
<Button
        android:id="@+id/processButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/str"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        />
</RelativeLayout>
This is the solution
Now to achieve  the Updated requirement add the above layout to layout-land folder in res (if you don't have one create a folder named layout-land in res ) now in default layout folder add this xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center"  >
<ru.mw.widget.DrawableImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:adjustViewBounds="true"
     />
<Button
    android:id="@+id/processButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView"
    android:layout_centerHorizontal="true"
    android:text="@string/str" />
<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/imageView"
    android:layout_centerHorizontal="true"
    android:text="@string/str"
    android:textColor="?android:attr/textColorTertiary" />
</RelativeLayout>
Thats it.
Try to add android:layout_alignParentBottom="true" to the button:
<Button
    android:id="@+id/processButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/str"
    android:layout_below="@+id/imageView"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    />
layout_alignParentBottom="true".ImageView between the TextView and Button
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center_vertical"  >
<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/str"
        android:textAppearance="@android:style/TextAppearance.Small"
        android:textColor="?android:attr/textColorTertiary"
        android:layout_centerHorizontal="true"
        />
<Button
        android:id="@+id/processButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/str"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        />
<ru.mw.widget.DrawableImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:layout_above="@+id/processButton"
        android:adjustViewBounds="true"
        android:layout_centerHorizontal="true"
        android:scaleType="centerCrop"
        />
</RelativeLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With