【问题标题】:android - loaded image's height it bigger than actual imageandroid - 加载图像的高度大于实际图像
【发布时间】:2014-11-29 12:47:30
【问题描述】:

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

// loading of the image into the ImageView
new DownloadImageTask(MyImageView).execute("ImageURL");

问题是,每次加载图像时,它的高度都不一样,即使 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" />

这里是图片

有时会发生这种情况:

有时会发生这种情况:

有什么想法吗?我只想让它与它的实际大小完全一致

谢谢!

【问题讨论】:

  • 您可以在任务结束时调整 ImageView 的大小
  • 感谢您的评论。听起来不错,但我需要动态获取图像的实际宽度和高度,然后进行设置

标签: android imageview size pixels


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-03
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    相关资源
    最近更新 更多