![](/img/trans.png)
[英]Android: How to stretch an image to the screen width while maintaining aspect ratio?
[英]Android Show Images while maintaining Aspect Ratio
我正在開發一個在某些活動中顯示圖像(通過使用相機拍攝或從圖庫中選擇)的應用程序。 我面臨的問題是顯示不同尺寸的圖像。 即使同一部手機的攝像頭拍攝的圖像很大,圖像的實際尺寸也很大。 因此,如果我在ImageView中顯示它們,則將得到擴展。
我曾在Facebook等某些應用中看到過,當圖像以全屏模式顯示時,它會保持我猜的縱橫比。 屏幕上會顯示整個圖像,無論其大小是多少,都不會被拉伸。 圖像會根據需要自動調整其高度和寬度。 如何實現相同的功能?
如何使ImageView能夠根據需要調整其高度和寬度(最大已定義)。
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="matrix"
android:src="@drawable/defaultimage"
android:padding="10dp" />
您需要在布局中使用其他android:scaleType
。 ImageView.ScaleType
文檔列出了可用的不同版本。 聽起來您可能想在示例fitCenter
matrix
更改為fitCenter
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.