Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中阻止图像挤压到imageview中_Android_Imageview - Fatal编程技术网

如何在android中阻止图像挤压到imageview中

如何在android中阻止图像挤压到imageview中,android,imageview,Android,Imageview,首先,我不确定我是否正确地表达了这个问题,但通过一些解释,我希望能让你明白我想问什么 我有一个图像视图,它位于屏幕上半部分的15%左右,比如说图像视图的高度是30px,但是我放在该图像视图中的图像的高度是100px。目前,图像的所有100px都挤到了30px中 我的问题是如何只显示图像的30px,而不显示压缩到30px中的完整100px 这是我的看法 <ImageView android:id="@+id/top_overlay" andro

首先,我不确定我是否正确地表达了这个问题,但通过一些解释,我希望能让你明白我想问什么

我有一个图像视图,它位于屏幕上半部分的15%左右,比如说图像视图的高度是30px,但是我放在该图像视图中的图像的高度是100px。目前,图像的所有100px都挤到了30px中

我的问题是如何只显示图像的30px,而不显示压缩到30px中的完整100px

这是我的看法

<ImageView
            android:id="@+id/top_overlay"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@drawable/background_section"
            app:layout_constraintBottom_toTopOf="@+id/top_guideline"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

将scaleType设置为居中。同时将背景设置为srcCompat。以下内容应在ConstraintLayout中起作用:

<ImageView
    android:id="@+id/top_overlay"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:srcCompat="@drawable/background_section"
    android:scaleType="center"
    app:layout_constraintBottom_toTopOf="@+id/top_guideline"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


您想显示该图像顶部的30px还是从中心显示30px,这无关紧要?从中心显示会更好imageview是ConstraintLayout的子级。不确定这是否有什么不同。将android:background更改为app:src这确实起到了作用,但是它不再与imageview的宽度匹配