Glide Android - 不显示所有图像

Glide Android - Doesn't show all the image

我必须在我的应用程序中拍照。拿到之后,我要在一个ImageView中显示,所以我决定用Glide作为库来处理它。

我设置的代码是这样的:

Glide.with(this)
                .load(mLastPhoto)
                .fitCenter()
                .centerCrop()
                .into(iv_circ_image);

并且 xml 文件如下所示:

<ImageView
                android:id="@+id/circ_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/bTakePicture"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="12dp"
                android:src="@drawable/ab_background_textured_" />

但是拍完后,图像是这样的:

如何设置 Glide 代码或 XML 以显示所有图像?

android:adjustViewBounds="true" 属性添加到您的 ImageView。如果您希望 ImageView 调整其边界以保留其可绘制对象的纵横比(来自 API-文档 http://developer.android.com/reference/android/widget/ImageView.html),请将此设置为 true。

<ImageView
    android:adjustViewBounds="true"
    android:id="@+id/circ_image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/bTakePicture"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="12dp"
    android:src="@drawable/ab_background_textured_" />

在 xml 中你有 android:layout_height="wrap_content"android:layout_marginTop="12dp"

然后在 java 你有 .fitCenter().centerCrop().

所以基本上你有一个 Glide 正在填充的 12dp 图像视图。我建议您设置图像视图的高度(即 200dp)或将按钮贴在屏幕底部并让图像视图填充它们之间可用的 space。