![](/img/trans.png)
[英]Android - ImageView - Multiple Screen Support - Set height/width as dp or match_parent/wrap_content?
[英]Display image with width as match parent and height as 200dp without stretching in android
我想在圖像視圖中以height=200dp
和width=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.