繁体   English   中英

显示图像的宽度为匹配父对象,高度为200dp,而无需在android中拉伸

[英]Display image with width as match parent and height as 200dp without stretching in android

我想在图像视图中以height=200dpwidth=match_parent来显示图像。通过使用height为200dp和width为match_parent,图像宽度与拍摄的相同。所以我尝试了android:scaleType =“ fitXY”但图像正在拉伸,这不是必需的。如何根据需要在ImageView中显示图像?

Xml:

<ImageView
                    android:id="@+id/ProfilePicIV"
                    android:layout_marginTop="20dp"
                    android:layout_height="170dp"
                    android:layout_width="match_parent"
                    android:layout_gravity="center"
                    android:scaleType="fitCenter"
                    android:adjustViewBounds="true"
                    android:layout_below="@+id/cropView"
                    />

这是我的xml代码。但是我无法按需要显示图像。我尝试了所有比例尺类型。android:scaleType =“ fitXY”将按我的意愿显示,但会进行图像拉伸。

使用最适合您图片的scaleType。 android:scaleType属性。

1. ImageView.ScaleType      CENTER
Center the image in the view, but perform no scaling. 

2. ImageView.ScaleType      CENTER_CROP
Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). 

3. ImageView.ScaleType      CENTER_INSIDE
Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). 

4. ImageView.ScaleType      FIT_CENTER
Scale the image using CENTER. 

5. ImageView.ScaleType      FIT_END
Scale the image using END. 

6. ImageView.ScaleType      FIT_START
Scale the image using START. 

7. ImageView.ScaleType      FIT_XY
Scale the image using FILL. 

8.ImageView.ScaleType   MATRIX
Scale using the image matrix when drawing.  

您可以使用它。

               <ImageView
                android:id="@+id/ProfilePicIV"
                android:layout_marginTop="20dp"
                android:layout_height="200dp"
                android:layout_width="match_parent"
                android:layout_gravity="center"
                android:scaleType="fitXY"
                app:srcCompat="@drawable/YourImage"
                android:adjustViewBounds="true"
                android:layout_below="@+id/cropView"
                />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM