【问题标题】:How to set Width of the image (in ImageView) without changing the width of the ImageView?如何在不改变 ImageView 宽度的情况下设置图像的宽度(在 ImageView 中)?
【发布时间】:2012-08-16 14:12:40
【问题描述】:

我想要做的是改变 ImageView 中图像的宽度而不影响 ImageView 的宽度。

    ----------------------------------------------------------------
    |                                                              |
    |                                                              |
    |         ----------------------------------------------       |
    |         |                                            |       |
    |         |                                            |       |
    |         |    this is the image( change its width)    |       |
    |         |                                            |       |
    |         ----------------------------------------------       |
    |                                                              |
    |      this is imageView the width mustnt change               |
    ----------------------------------------------------------------

我怎样才能做到这一点?请帮忙?

【问题讨论】:

  • 尝试为imageView.eg:android:padding="1dp"添加填充
  • 如何动态设置 padding imageView?

标签: java android imageview android-imageview


【解决方案1】:

您可以为此使用 ScaleType。 喜欢,

imgV.setScaleType(ImageView.ScaleType.CENTER_CROP);

你也可以指定 Padding 属性。

查看可能对您有帮助的链接。

Android ImageView adjusting parent's height and fitting width

【讨论】:

  • 工作!!我们也可以使用 setMargins(280, 480,80 , 80);对吗?
  • 没有 setMargins 用于在布局内设置图像.. 不是图像视图内的图像
  • Margin 将在 ImageView 控件之外留出空间,而 Padding 将在 ImageView 内留出空间,即留给其内容(例如图像)。
【解决方案2】:

ImageView 和 image 没有区别。为了在 Android 设备中显示图像,我们使用 ImageView。如果您想在某物的中心显示图像,则使用一些布局包装图像视图,并将图像设置在该布局内,并在您需要的所有边上添加一些填充。

【讨论】:

  • 但是当我们改变 imageview 的宽度时,图像保持它的纵横比
  • 会的。用布局包装图像视图并添加一些填充的图像视图。
猜你喜欢
  • 2016-04-01
  • 2023-03-18
  • 2015-12-14
  • 2010-12-16
  • 1970-01-01
  • 2013-02-06
  • 1970-01-01
  • 1970-01-01
  • 2019-03-09
相关资源
最近更新 更多