【问题标题】:Android imageview, scale full screen, and centerCropAndroid imageview、缩放全屏和centerCrop
【发布时间】:2013-01-28 02:53:09
【问题描述】:

我怎样才能有一个图像填充屏幕,但保持其纵横比,并适合中心?

目前我有大图像,比手机屏幕分辨率还大,但我怀疑它们会在分辨率更高的设备上被加黑

scaleType 的什么组合可以解决问题?

【问题讨论】:

    标签: android imageview


    【解决方案1】:

    您可以简单地使用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" />
    

    【讨论】:

    • android:scaleType="fitXY" 也用
    【解决方案2】:
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitCenter" />
    

    这是一个基本设置。

    【讨论】:

      【解决方案3】:

      我之前遇到过这个问题,问题是当图像需要放大时(屏幕宽度大于图像),Android 不会将图像缩放到超出其给定大小。但是,按比例缩小效果很好。

      我最终创建了下面提到的AspectRatioImageView,效果很好。请务必阅读有关 getIntrinsicWidth() 返回 0 和 getDrawable() 返回 null 的 cmets,并对它们进行一些安全检查。

      How to stretch three images across the screen preserving aspect ratio?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-12-25
        • 1970-01-01
        • 2018-05-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-04
        • 1970-01-01
        相关资源
        最近更新 更多