【问题标题】:ImageView does not center scaled down images properlyImageView 无法正确居中缩小图像
【发布时间】:2011-07-23 03:45:30
【问题描述】:


我无法让图像在 ImageView 中正确缩放和居中。
放大的时候没有问题,但是缩小的时候,图像不再居中,ImageView的边界不对,像这样:

problem.png

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/stereomood_splash"
        android:scaleType="fitCenter"
        android:id="@+id/imageView1"
        android:layout_width="100dip"
        android:layout_height="200dip"></ImageView>
</LinearLayout>

这是一个错误吗?有人找到解决方法吗?

【问题讨论】:

    标签: android android-layout android-imageview


    【解决方案1】:

    您应该将android:adjustViewBounds="true" 设置为this answer

    您还需要将android:layout_widthandroid:layout_height 设置为wrap_content,否则我相信您的硬编码边界将覆盖任何视图边界调整。

    【讨论】:

    • 您好,感谢您的回复。也请查看我的回答。道歉 - 我的示例图像出错了 - 它不应该像它那样显示被捕捉到新图像大小的边界。顺便说一句,将其设置为“on”会导致整个图像在 XML 编辑器中不可见。
    【解决方案2】:

    编辑:将其放在这里,因为它与遇到相同症状的人有关。

    此问题仅存在于 XML 编辑器中 - 在真实手机或模拟器上,图像的大小和位置都正确。根据特定图像和ImageView 尺寸,编辑器预览将显示图像大小调整不正确和/或超出视图范围。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 2014-06-02
      • 1970-01-01
      • 2016-03-22
      • 1970-01-01
      • 2020-10-12
      • 1970-01-01
      相关资源
      最近更新 更多