İsmail DERVİŞOĞLU
İsmail DERVİŞOĞLU

Reputation: 385

Remove extra space from ConstraintLayout inside ImageView

I use ConstraintLayout, Guideline and ImageView together for responsive view. I am getting extra spacing on the top and bottom on ImageView. I tried android: adjustViewBounds and android: scaleType but it didn't work How can I clear it out?

Here is what it looks like:

enter image description here

Here is the code:

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

    <androidx.constraintlayout.widget.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/left_guideline"
        app:layout_constraintGuide_percent=".20"
        android:orientation="vertical"/>

    <androidx.constraintlayout.widget.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/right_guideline"
        app:layout_constraintGuide_percent=".80"
        android:orientation="vertical"/>

        <ImageView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:adjustViewBounds="true"
            app:layout_constraintStart_toStartOf="@+id/left_guideline"
            app:layout_constraintEnd_toEndOf="@+id/right_guideline"
            app:layout_constraintDimensionRatio="w,1:1"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:src="@drawable/logoo" />

</androidx.constraintlayout.widget.ConstraintLayout>

Upvotes: 2

Views: 744

Answers (2)

Tayyab Mazhar
Tayyab Mazhar

Reputation: 1702

So, I used your layout:

enter image description here

Then added this to ImageView:

android:scaleType="centerCrop"

And this is the result:

enter image description here

So just add android:scaleType="centerCrop" in your imageView and that should do it.

Upvotes: 2

Amit Gupta
Amit Gupta

Reputation: 663

If you want the view to take all space then, Could you try scaleType in your ImageView.

android:scaleType="fitXY"

ImageView

<ImageView
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:adjustViewBounds="true"
    app:layout_constraintStart_toStartOf="@+id/left_guideline"
    app:layout_constraintEnd_toEndOf="@+id/right_guideline"
    app:layout_constraintDimensionRatio="w,1:1"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:src="@drawable/logoo"
    android:scaleType="fitXY"
    />

If this is not what you want, then please comment.

Upvotes: 0

Related Questions