图像不适合高度

时间:2017-11-20 15:33:24

标签: android imageview

我有一张图片,宽度大于高度。我希望通过裁剪宽度来适合高度的图像。它应该保存ascpectRatio。图像应适合图像视图。 我尝试在XML中使用android:scaleType="centerCrop"属性,但我没有得到相同的结果。

我试过了 android:scaleType="fitXY" android:adjustViewBounds="true"

你能帮助我吗? 下面是XML文件。

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="riskmatix.be.bouwcampusvirtualtour.home.HomeActivity">

<ImageView
    android:id="@+id/background_image"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:src="@drawable/day"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

1 个答案:

答案 0 :(得分:0)

试试这个, 你需要将宽度和高度设置为match_parent

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/ati"
    android:scaleType="centerCrop"
    android:adjustViewBounds="true"/>