Sneha Patil
Sneha Patil

Reputation: 67

Image is not covering full background

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

Upvotes: 0

Views: 286

Answers (1)

Abdur Rahman
Abdur Rahman

Reputation: 1001

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.

Upvotes: 1

Related Questions