[英]Android image change image dimensions according to device screen size
我有一個imageView
誰的寬度是"match_parent"
(兩端都有一些邊距)。
由於不同的設備具有不同的寬度,因此圖像不會填充imageView,而是在兩端各留一些間隙,這取決於我在哪個設備上查看圖像。
我嘗試了android:adjustViewBounds="true"
但這會拉伸圖像以填充寬度,從而嚴重扭曲了內容。
正確的方法是什么? 我應該為Android提供具有不同尺寸的圖像的多個副本(例如針對不同像素密度的多個drawable文件夾)嗎?
嘗試將scaleType設置為“ fitXY”,但這仍在拉伸圖像而不保持縱橫比。
這是我的xml:
<ImageView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="110dp"
android:scaleType="fitXY"
android:src="@drawable/inner_map"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header" />
如果這很重要,我已將具有該圖像不同分辨率的多個副本插入到不同的可繪制文件夾中
<ImageView
android:id="@id/img"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop" />
https://developer.android.com/reference/android/widget/ImageView.ScaleType
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.