【问题标题】:Android Show Images while maintaining Aspect RatioAndroid 在保持纵横比的同时显示图像
【发布时间】:2015-01-29 18:54:45
【问题描述】:

我正在开发一个应用程序,该应用程序在某些活动中显示图像(通过使用相机拍摄或从图库中选择)。我面临的问题是显示不同尺寸的图像。即使同一部手机的摄像头拍摄的图像尺寸很大,图像的实际尺寸也很大。因此,如果我在 ImageView 中显示它们,就会被拉伸。

我在 Facebook 等一些应用程序中看到,当图像以全屏模式显示时,它会保持我猜的纵横比。整个图像,无论其大小如何,都会显示在屏幕上,但不会被拉伸。图像会根据需要自动调整其高度和宽度。如何实现相同的功能?

如何制作能够根据需要调整其高度和宽度(已定义最大值)的 ImageView。

   <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:scaleType="matrix"
        android:src="@drawable/defaultimage"
        android:padding="10dp" />

【问题讨论】:

    标签: java android image aspect-ratio


    【解决方案1】:

    您需要在布局中使用不同的android:scaleTypeImageView.ScaleType 文档列出了可用的不同文档。听起来您可能想在示例中将 matrix 更改为 fitCenter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-20
      • 2019-05-12
      相关资源
      最近更新 更多