title: Image stretched when set as background in the Relative layout
body: <p>I am capturing image from camera and sending it to the server .I am displaying the captured image in the background of <code>RelativeLayout</code> using the following code:</p>
  
  <pre><code>private void previewMedia(boolean isImage) {
      // Checking whether captured media is image or video
      if (isImage) {
          Log.e("Preview Media", "Called");
          BitmapFactory.Options options = new BitmapFactory.Options();
  
          // down sizing image as it throws OutOfMemory Exception for larger images
          options.inSampleSize = 8;
          //options.inScaled = false;
  
          Log.e("File URI", String.valueOf(fileUri));
  
          final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(), options);
          //Uploading image to server
          new UploadFileToServer().execute();
          Log.e("DownSizing image", "Called");
          Drawable dr = new BitmapDrawable(bitmap);
          Log.e("DrawableN", String.valueOf(dr));
          relativeLayout.setBackgroundDrawable(dr);
      }
  }
  </code></pre>
  
  <p>Inside the code ,I am downsizing the image to avoid <code>OutOfMemory Exception</code>.While setting the image in the <code>background</code> of Relative Layout ,image got stretched.Screenshot is given below:</p>
  
  <p><a href="https://i.stack.imgur.com/kX0B9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kX0B9.png" alt="Stretched Image "></a></p>
  
  <p><strong>XML code:</strong></p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:padding="@dimen/padding10"&gt;
  
      &lt;RelativeLayout
          android:id="@+id/rel"
          android:layout_width="match_parent"
          android:layout_height="150dp"
          android:layout_marginBottom="@dimen/margin10"
          android:layout_marginLeft="@dimen/margin10"
          android:layout_marginRight="@dimen/margin10"
          android:layout_marginTop="@dimen/margin10"&gt;
  
          &lt;ImageView
              android:id="@+id/arrowProfile"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:layout_alignParentTop="true"
              android:paddingLeft="@dimen/padding10"
              android:src="@drawable/back_signup" /&gt;
  
          &lt;com.almabay.almachat.circularImageView.CircularImageView
              android:id="@+id/cam"
              android:layout_width="50dp"
              android:layout_height="50dp"
              android:layout_alignParentRight="true"
              android:paddingRight="@dimen/padding10"
              android:background="@drawable/camera1"/&gt;
  
          &lt;TextView
              android:id="@+id/userName"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_above="@+id/status"
              android:layout_alignParentBottom="true"
              android:layout_marginBottom="@dimen/margin20"
              android:paddingLeft="@dimen/padding10"
              android:text="User Name"
              android:textColor="#ffffff"
              android:textSize="20sp" /&gt;
  
          &lt;TextView
              android:id="@+id/status"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:paddingLeft="@dimen/padding10"
              android:text="Status of user"
              android:textColor="#ffffff" /&gt;
      &lt;/RelativeLayout&gt;
  
      &lt;ScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_below="@+id/rel"
          android:background="@color/divider_background"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
  
              android:layout_marginRight="@dimen/margin10"
              android:layout_marginTop="@dimen/margin10"
              android:background="@color/divider_background"
              android:orientation="vertical"&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_marginBottom="@dimen/margin10"
                  android:background="#ffffff"
                  android:orientation="vertical"
                  android:paddingLeft="@dimen/padding10"&gt;
  
                  &lt;TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="First Name"
                      android:textStyle="bold" /&gt;
  
                  &lt;TextView
                      android:id="@+id/firstNameProfile"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Ashish" /&gt;
  
                  &lt;View
                      android:layout_width="match_parent"
                      android:layout_height="@dimen/divider_height"
                      android:layout_marginBottom="@dimen/margin10"
                      android:layout_marginTop="@dimen/margin10"
                      android:background="@color/divider_background" /&gt;
  
                  &lt;TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Last Name"
                      android:textStyle="bold" /&gt;
  
                  &lt;TextView
                      android:id="@+id/lastNameProfile"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Kumar" /&gt;
  
                  &lt;View
                      android:layout_width="match_parent"
                      android:layout_height="@dimen/divider_height"
                      android:layout_marginBottom="@dimen/margin10"
                      android:layout_marginTop="@dimen/margin10"
                      android:background="@color/divider_background" /&gt;
  
                  &lt;TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Birthday"
                      android:textStyle="bold" /&gt;
  
                  &lt;TextView
                      android:id="@+id/birthday"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="03 December" /&gt;
  
                  &lt;View
                      android:layout_width="match_parent"
                      android:layout_height="2dp"
                      android:layout_marginBottom="@dimen/margin10"
                      android:layout_marginTop="@dimen/margin10"
                      android:background="@color/divider_background" /&gt;
  
                  &lt;TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Gender"
                      android:textStyle="bold" /&gt;
  
                  &lt;TextView
                      android:id="@+id/gender"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:paddingBottom="@dimen/padding10"
                      android:text="Female" /&gt;
  
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_marginBottom="@dimen/margin10"
                  android:background="@color/while_color"
                  android:orientation="vertical"
                  android:paddingLeft="@dimen/padding10"&gt;
  
                  &lt;RelativeLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"&gt;
  
                      &lt;TextView
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_alignParentLeft="true"
                          android:paddingTop="@dimen/padding10"
                          android:text="Status"
                          android:textStyle="bold" /&gt;
  
                      &lt;ImageView
                          android:id="@+id/imgEdit"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_alignParentRight="true" /&gt;
                  &lt;/RelativeLayout&gt;
  
                  &lt;View
                      android:layout_width="match_parent"
                      android:layout_height="@dimen/divider_height"
                      android:layout_marginBottom="@dimen/margin10"
                      android:layout_marginTop="@dimen/margin10"
                      android:background="@color/divider_background" /&gt;
  
                  &lt;TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:paddingBottom="@dimen/padding10"
                      android:text="Displaying the status message here" /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_marginBottom="@dimen/margin10"
                  android:background="@color/while_color"
                  android:orientation="vertical"
                  android:paddingLeft="@dimen/padding10"&gt;
  
                  &lt;RelativeLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"&gt;
  
                      &lt;TextView
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_alignParentLeft="true"
                          android:text="Email"
                          android:textStyle="bold" /&gt;
  
                      &lt;ImageView
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_alignParentRight="true" /&gt;
                  &lt;/RelativeLayout&gt;
  
                  &lt;View
                      android:layout_width="match_parent"
                      android:layout_height="@dimen/divider_height"
                      android:layout_marginBottom="@dimen/margin10"
                      android:layout_marginTop="@dimen/margin10"
                      android:background="@color/divider_background" /&gt;
  
  
                  &lt;TextView
                      android:id="@+id/emailProfile"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:paddingBottom="@dimen/padding10"
                      android:text="Email ID" /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_marginBottom="@dimen/margin10"
                  android:background="@color/while_color"
                  android:orientation="vertical"
                  android:paddingLeft="@dimen/padding10"&gt;
  
                  &lt;RelativeLayout
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:paddingTop="@dimen/padding10"&gt;
  
                      &lt;TextView
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_alignParentLeft="true"
                          android:text="Phone"
                          android:textStyle="bold" /&gt;
  
                      &lt;ImageView
                          android:layout_width="30dp"
                          android:layout_height="30dp"
                          android:layout_alignParentRight="true" /&gt;
                  &lt;/RelativeLayout&gt;
  
                  &lt;View
                      android:layout_width="match_parent"
                      android:layout_height="@dimen/divider_height"
                      android:layout_marginBottom="@dimen/margin10"
                      android:background="@color/divider_background" /&gt;
  
                  &lt;TextView
                      android:id="@+id/mobile"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:paddingBottom="@dimen/padding10"
                      android:text="13464646466" /&gt;
  
              &lt;/LinearLayout&gt;
  
          &lt;/LinearLayout&gt;
      &lt;/ScrollView&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Please help to fix the issue.I am using width as match_parent and height as 150dp for the RelativeLayout.</p>