【问题标题】:How to display an image full size with ImageView?如何使用 ImageView 显示全尺寸图像?
【发布时间】:2013-07-10 07:27:04
【问题描述】:

当我尝试以全尺寸显示图像时遇到问题。 我试图用 wrap_content 显示图像。但它是较小的真实图像。

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/screen1_logo" />

我转到此图像的属性并查看一些信息:尺寸 211 x 74。然后我尝试显示具有固定宽度和高度的图像。我发现它更大了。

<ImageView
        android:layout_width="211px"
        android:layout_height="74px"
        android:src="@drawable/screen1_logo" />

这是正确的方式吗?我们是否必须固定尺寸才能以全尺寸显示图像? 请帮我解释和解决这个问题。

【问题讨论】:

    标签: android image imageview


    【解决方案1】:

    在您的 ImageView 中添加 scaleType

     <ImageView
         android:scaleType="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/screen1_logo" />
    

    来自文档android:scaleType="center"

    图像在视图中居中,但不执行缩放。

    【讨论】:

    • 我用所有可用值尝试了 android:scaleType。但图像显示相同
    • 你把位图放在哪里了?你把它放在 res/drawable 文件夹之一吗?
    • 我把它放到drawable-hdpi文件夹中
    • 你的手机有密度 hdpi 的屏幕吗?
    • res/drawable 在加载时可能不会对位图执行缩放过程。您应该阅读屏幕支持指南,here
    【解决方案2】:

    尝试在 xml 文件中添加(ImageView 属性)android:adjustViewBounds="true"。

    <ImageView
        android:id="@+id/photoViewer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
    

    【讨论】:

      【解决方案3】:

      尝试在视图中添加 scaleType 属性:

      android:scaleType=""
      

      可以在这里找到可用的选项:

      http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

      【讨论】:

      • 如果您查看链接,将解释可用选项。听起来你想要 android:scaleType="centerInside"
      • :(我也试了,不过实物图还是小了点
      • 我不确定我理解你的意思。你是说你想让图片比它大吗?
      • 你可以改变android:layout_width="match_parent" 和"android:layout_height="match_parent" 让imageView更大?
      【解决方案4】:

      请将比例类型定义为 fitXY

       <ImageView
                  android:id="@+id/yourImageViewId"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:scaleType="fitXY" />
      

      【讨论】:

        【解决方案5】:

        【讨论】:

        • 我不这么认为。因为我尝试使用所有可用值设置 scaleType
        【解决方案6】:
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:layout_marginStart="0dp"
            android:layout_marginTop="0dp"
            android:layout_marginBottom="40dp"
            android:scaleType="centerInside"
        

        不要让 width/height = wrap_content 很重要,因为这样你的 imageView 大小等于照片,所以不能移动。

        在这里你可以看到会是什么样子。 https://guides.codepath.com/android/Working-with-the-ImageView

        【讨论】:

          猜你喜欢
          • 2017-05-10
          • 1970-01-01
          • 2014-11-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-11-24
          • 2018-02-04
          • 2015-12-14
          相关资源
          最近更新 更多