0

I am building a chat application and when I send an image to the user, the image is not covering the background that I have given instead It is giving wired padding top and bottom. How to solve this issue. The padding that I have given is 7dp to each side here is my code

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp">
    <android.support.constraint.ConstraintLayout
        android:layout_width="wrap_content"
        android:id="@+id/photo"
        android:background="@drawable/toolbar_background"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/imageContentUser"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:src="@drawable/doc"
            android:padding="0dp"
            android:adjustViewBounds="true"
            app:layout_constraintRight_toRightOf="parent" />
    </android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>

enter image description here I expect this to be the result. enter image description here But I am getting this as result

Aniket Sahrawat
  • 12,410
  • 3
  • 41
  • 67
Sneha Patil
  • 67
  • 1
  • 9
  • Why don't you [research](https://stackoverflow.com/questions/16135984/full-screen-background-image-in-an-activity) first. I came here by [java](https://stackoverflow.com/questions/tagged/java) tag. You should not tag unnecessarily. – Aniket Sahrawat Jan 15 '18 at 09:01
  • Possible duplicate of [Full screen background image in an activity](https://stackoverflow.com/questions/16135984/full-screen-background-image-in-an-activity) – Aniket Sahrawat Jan 15 '18 at 09:02
  • 1
    you can google before post question...remove android:src="@drawable/doc" and use android:background="@drawable/doc" , android:scaleType="fitXY" – Ajay Pandya Jan 15 '18 at 09:10

1 Answers1

1

You need to use

android:scaleType="fitXY"

Scale type has many values like matrix, fitXY, fitStart, fitCenter, firEnd, center, centerCrop, centerInside

You use fitXY, It'll cover the all Screen if you choose it to match_parentor maybe your desired length and width

It should be like this finally :

<ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/ic_background_image" />

Hope this will work for you.

Abdur Rahman
  • 894
  • 1
  • 11
  • 27