How can I set the RelativeLayout to the screen?

I am facing issues that appear on screen off-screen RelativeLayout. ImageViewIt does not allow you to scale the image to make the button image visible.

What I have:

enter image description here

What I want:

enter image description here

the 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 changing the screen orientation: If I use the Arun C Thomas method in landscape mode, everything is fine, but in portrait mode I have this (the image is cropped left / right):

enter image description here What is expected:

enter image description here

+5
source share
3 answers
<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 decision

layout-land res ( layout-land res) layout 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>

.

+2

android:layout_alignParentBottom="true" :

<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"
    />
+1
  • Align the button with the bottom of the parent using layout_alignParentBottom="true".
  • Wrap ImageViewbetween TextViewandButton

<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>
+1
source

All Articles