简体   繁体   English

Android imageview,缩放全屏和centerCrop

[英]Android imageview, scale full screen, and centerCrop

How can I have an imageview whose image fills the screen, but maintains its aspect ratio, and fits in the center? 如何使用图像填充屏幕的图像视图,但保持其纵横比,并适合中心?

Currently I have large images, larger than phone screen resolution, but I suspect that they will be be letterboxed on devices with higher resolution 目前我有大图像,大于手机屏幕分辨率,但我怀疑它们将被装在具有更高分辨率的设备上

What combination of scaleType will do the trick? scaleType哪种组合可以scaleType

You could simply use adjustViewBounds value to maintain the aspect ratio of the image 您可以简单地使用adjustViewBounds值来维护图像的纵横比

<ImageView
        android:id="@+id/metallicaImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:adjustViewBounds="true"
        android:src="@drawable/metallica" />
<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="fitCenter" />

It's a basic setting. 这是一个基本设置。

I've run into this before, the issue is that when the image needs to be scaled up (screen width is larger than the image), Android won't scale the image beyond its given size. 我之前遇到过这个问题,问题是当图像需要按比例放大(屏幕宽度大于图像)时,Android不会将图像缩放到超出给定大小的范围。 However, scaling down works just fine. 但是,按比例缩小效果很好。

I ended up creating the AspectRatioImageView mentioned below, works well. 我最终创建了下面提到的AspectRatioImageView ,效果很好。 Be sure to read the comments about getIntrinsicWidth() returning 0 and getDrawable() returning null, and put in some safety checks for those. 请务必阅读有关getIntrinsicWidth()返回0和getDrawable()返回null的注释,并对其进行一些安全检查。

How to stretch three images across the screen preserving aspect ratio? 如何在屏幕上拉伸三个图像以保持纵横比?

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

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