简体   繁体   English

如何使用 ImageView 显示全尺寸图像?

[英]How to display an image full size with ImageView?

I have problem when I try to display the image with full size.当我尝试以全尺寸显示图像时遇到问题。 I tried to display image with wrap_content.我试图用 wrap_content 显示图像。 But it is smaller real image.但它是较小的真实图像。

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

在此处输入图片说明

I go to the properties of this image and see some information: dimentions 211 x 74. Then I try to display image with fixed width and height.我转到此图像的属性并查看一些信息:尺寸 211 x 74。然后我尝试显示具有固定宽度和高度的图像。 I see it's bigger.我看它更大。

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

带有 wrap_content 的 ImageView is it right way?这是正确的方法吗? do we must to fix size to display image with full size?我们必须固定大小以显示全尺寸图像吗? Please help me to explain and resolve this problem.请帮我解释和解决这个问题。

add a scaleType to your ImageViewscaleType添加到您的 ImageView

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

from the doc android:scaleType="center"来自文档android:scaleType="center"

Center the image in the view, but perform no scaling.在视图中居中图像,但不执行缩放。

Try adding in xml file (ImageView properties) android:adjustViewBounds="true".尝试添加 xml 文件(ImageView 属性)android:adjustViewBounds="true"。

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

Try adding a scaleType attribute to your view:尝试将 scaleType 属性添加到您的视图中:

android:scaleType=""

The available options can be found here:可用选项可在此处找到:

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

Please Define scale type as fitXY请将比例类型定义为 fitXY

 <ImageView
            android:id="@+id/yourImageViewId"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY" />
    android:layout_width="match_parent"
    android:layout_height="160dp"
    android:layout_marginStart="0dp"
    android:layout_marginTop="0dp"
    android:layout_marginBottom="40dp"
    android:scaleType="centerInside"

It's important don't to have width/height = wrap_content because in that way your imageView size is equal to photos so it can't be moved.重要的是不要有 width/height = wrap_content 因为这样你的 imageView 大小等于照片所以它不能移动。

Here you can see what is going to look like.在这里你可以看到会是什么样子。 https://guides.codepath.com/android/Working-with-the-ImageView https://guides.codepath.com/android/Working-with-the-ImageView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM