【问题标题】:Image view content not filling it self图像视图内容不自行填充
【发布时间】:2016-05-30 13:57:00
【问题描述】:

这是我的情况,我有一个这样的图像视图:

你能看到我的“+”符号不在我的“没有头像”图片的末尾,那是因为这张图片没有填满它的 imageView。

我已经尝试过 android:adjustViewBounds="true"android:scaleType="fitXY" 就像在 Unwanted padding around an ImageView 中所说的那样,但它对我不起作用。

有什么想法吗?

编辑:

我忘记了我的布局:

<RelativeLayout
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_marginTop="10dp"
        android:id="@+id/iv_profile_picture"
        android:layout_width="140dp"
        android:layout_height="140dp"
        android:adjustViewBounds="true"
        android:src="@mipmap/ic_no_image_profile"
        />

    <ImageButton
        android:src="@mipmap/ic_new_image_profile"
        android:background=""
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignRight="@+id/iv_profile_picture"
        android:layout_alignEnd="@+id/iv_profile_picture"
        android:layout_alignBottom="@+id/iv_profile_picture"/>

</RelativeLayout>

【问题讨论】:

  • 如果您使用任何类型的图像加载器库,请确保它没有覆盖您在 xml 布局中设置的比例类型
  • @MuchOverflow 我想我没有使用任何库来加载图像
  • 你应该使用drawable文件夹来放置你的图片文件。 mipmap 文件夹应仅用于放置应用启动器图标文件。参考这个:stackoverflow.com/a/28065664/3533289我认为这可能是问题
  • 可能是您的图片包含填充。
  • @umerk44 我不这么认为,我尝试了其他图像,我得到了相同的结果:(

标签: android imageview android-imageview


【解决方案1】:

你可以这样做:

从您的 xml 中删除 android:layout_marginTop="10dp"

您的 xml 代码应如下所示:

<ImageView
        android:id="@+id/iv_profile_picture"
        android:layout_width="140dp"
        android:layout_height="140dp"
        android:scaleType="fitXY"
        android:adjustViewBounds="true"
        android:src="@mipmap/ic_no_image_profile"
        />

希望这会对你有所帮助。

【讨论】:

  • 这里不行,图片没有填满imageview
  • @guisantogui,你能把src改成后台吗?
  • 我这样做了,但它并没有改变图像行为。 :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多