简体   繁体   English

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

[英]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=200dpwidth=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.

相关问题 Android-ImageView-多屏支持-将高度/宽度设置为dp还是match_parent / wrap_content? - Android - ImageView - Multiple Screen Support - Set height/width as dp or match_parent/wrap_content? 即使 layout_constraintHeight_max/min 设置为 200dp,高度也不正确 - height is incorrect even with layout_constraintHeight_max/min set to 200dp Android 图像裁剪库图像在宽度和高度上没有匹配父级 - Android Image Cropper Library Image is not getting Match Parent in width and Height LinearLayout layout:width =“ match_parent”和layout:height =“ match_parent”不断更改为固定的dp - LinearLayout layout:width=“match_parent” and layout:height=“match_parent” keeps changing to a fixed dp 动画以200dp上下移动视图 - Animation to move view with 200dp upside/downside 宽度和高度的壁画图像 - match_parent不显示 - Fresco Image with both width and height - match_parent doesn't display 图像在图像按钮中按宽度和高度拉伸 - Image is stretching in imagebutton as per width and height Android:启动器图标DP中的宽度和高度 - Android: Launcher Icon width and height in DP Android 并以 dp 单位编程设置宽度和高度 - Android and setting width and height programmatically in dp units 如何设置图片/ WebView的高度/宽度以匹配父级? - How to set image/WebView height/width to match the parent?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM