android - 加载图像的高度比实际图像大

Ofe*_*mon 2 size android pixels imageview

我正在使用 AsyncTask 类从网络加载图像,并将其设置为我的代码中的图像视图。

// loading of the image into the ImageView
new DownloadImageTask(MyImageView).execute("ImageURL");
Run Code Online (Sandbox Code Playgroud)

问题是,每次加载图像时,它的高度都是不同的,即使 ImageView 的宽度和高度是 warp_content。我添加了一种带有背景和填充的边界线以查看它的实际高度。 这是xml

<ImageView
    android:id="@+id/ivBigRecipeImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_margin="5dp"
    android:layout_toRightOf="@+id/ingredientsTitle"
    android:background="#52D017"
    android:contentDescription="food"
    android:padding="1dp" />
Run Code Online (Sandbox Code Playgroud)

在这里是照片

有时会发生这种情况:

在此处输入图片说明

有时会发生这种情况:

在此处输入图片说明

有任何想法吗?我只想让它的实际大小

谢谢!

rom*_*4ek 5

尝试添加android:adjustViewBounds="true"到您的ImageView,它应该可以工作。