从 ImageView 中的 ConstraintLayout 中删除多余的 space

Remove extra space from ConstraintLayout inside ImageView

我将 ConstraintLayout、Guideline 和 ImageView 一起用于响应式视图。我在 ImageView 的顶部和底部获得了额外的间距。我尝试了 android: adjustViewBoundsandroid: scaleType 但没有用 我怎样才能清除它?

这是它的样子:

代码如下:

<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>

如果你想让视图占据所有 space 那么,你可以在你的 ImageView 中尝试 scaleType

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"
    />

如果这不是您想要的,请发表评论。

所以,我使用了你的布局:

然后将其添加到 ImageView:

android:scaleType="centerCrop"

这是结果:

所以只需在您的 imageView 中添加 android:scaleType="centerCrop" 即可。