如何保持图像的纵横比并填充屏幕宽度?

时间:2014-11-16 06:04:49

标签: android imageview aspect-ratio adjustviewbounds

我正在尝试通过保持纵横比来调整图像大小。它应该足够大以填充屏幕宽度,如果需要,一些图像应该在屏幕外。

here is a picture of what I want

我试过

  

机器人:adjustViewBounds

但是当图像大于屏幕时,它会将图像放入imageView而不会填充宽度。

我也不想使用:

android:scaleType="centerCrop"

这是我的完整代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imageBackgroundAboutFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:adjustViewBounds="true"
        android:src="@drawable/about_us_background"/>
</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

android:scaleType="fitXY"android:adjustViewBounds

一起使用

<强>更新

我认为你应该做一些试验和错误:

How to scale an Image in ImageView to keep the aspect ratio

Scale Image to fill ImageView width and keep aspect ratio

这么多可能的修复,但我不确定哪一个适合你(我的答案为我工作但不适合你 - 例如)。

答案 1 :(得分:0)

像这样更新你的imageview ..

删除scaleType和adjustViewBounds ..并将layout_height设为match_parent

<ImageView
    android:id="@+id/imageBackgroundAboutFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/about_us_background"/>
相关问题