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?
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.
Use scaleType that best suits your picture. android:scaleType
property for this.
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"
/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.