【问题标题】:How to maintain the aspect ratio of the image and fill the screen width?如何保持图像的纵横比并填充屏幕宽度?
【发布时间】:2014-11-16 06:04:49
【问题描述】:

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

here is a picture of what I want

我试过了

android: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>

【问题讨论】:

    标签: android imageview aspect-ratio adjustviewbounds


    【解决方案1】:

    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

    这么多可能的解决方法,但我不确定哪一个对你有用(例如,我的答案对我有用,但对你没有用)。

    【讨论】:

    • 我试过了,但它没有保持纵横比:
    • 嗯..它在我的情况下保持图像的比例
    • thanx,但事实并非如此。你觉得父母重要吗?我使用相对布局。
    • @user293171 并查看我的链接,人们在自己的情况下有不同的答案
    • 我想让图片填满屏幕宽度!
    【解决方案2】:

    像这样更新你的图像视图..

    移除 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"/>
    

    【讨论】:

    • thanx 但如果图像很高,它不会填满整个页面。
    猜你喜欢
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 1970-01-01
    相关资源
    最近更新 更多