[英]Display image with width as match parent and height as 200dp without stretching in android
I want to display the image in image view with height=200dp
and width=match_parent
.By using height as 200dp and width as match_parent, the image width is same as it is taken.So I have tried android:scaleType="fitXY" but the image is stretching which is not required.How can i display image in ImageView as I want? 我想在图像视图中以
height=200dp
和width=match_parent
来显示图像。通过使用height为200dp和width为match_parent,图像宽度与拍摄的相同。所以我尝试了android:scaleType =“ fitXY”但图像正在拉伸,这不是必需的。如何根据需要在ImageView中显示图像?
Xml: 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"
/>
This is my xml code.But I am not able to display image as I want.I tried with all scale types.android:scaleType="fitXY" will display as I wanted but with the image stretching. 这是我的xml代码。但是我无法按需要显示图像。我尝试了所有比例尺类型。android:scaleType =“ fitXY”将按我的意愿显示,但会进行图像拉伸。
Use scaleType that best suits your picture. 使用最适合您图片的scaleType。
android:scaleType
property for this. 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.
You can use this. 您可以使用它。
<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.