kartoos khan
kartoos khan

Reputation: 449

Remove white spaces around image view

I have used an image view inside constrains layout and set height and width to Zero and added height and width percentage. But when I add the height and width percentage it adds whites spaces on top and bottom of the image how can I remove these white spaces from top and bottom of image. I have tried

android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="fitXY"

But the white apces are not removed. Here is xml for image view.

<ImageView
        android:id="@+id/iv_conf_call"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintHeight_percent="0.1"
        app:layout_constraintWidth_percent="0.1"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:background="@drawable/ripple_with_background"
        android:contentDescription="@null"
        android:onClick="btnCall_Clicked"
        android:padding="10dp"
        android:src="@android:drawable/sym_action_call"
        android:tint="@color/white"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/iv_waiting" />

I wan to remove yellow highlighted white space shown in picture. enter image description here

ripple_with_background.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:drawable="@color/colorPrimaryDark" android:shape="oval" />
    </item>
    <item android:drawable="@drawable/icon_round_background" />
</selector>

icon_round_backgroun.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="0dp"
    android:shape="ring"
    android:thicknessRatio="2"
    android:useLevel="false">
    <solid android:color="@color/colorPrimary" />

</shape>

Upvotes: 2

Views: 778

Answers (1)

Miroslav Toffolon
Miroslav Toffolon

Reputation: 58

Could you try to set aspect ratio to the image?

app:layout_constraintDimensionRatio="H,16:9"

in your case should be 1:1

Upvotes: 2

Related Questions