Reputation: 385
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:
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
Reputation: 1702
So, I used your layout:
Then added this to ImageView:
android:scaleType="centerCrop"
And this is the result:
So just add android:scaleType="centerCrop"
in your imageView and that should do it.
Upvotes: 2
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