我有一個ImageView具有固定的高度和寬度(比如寬度爲100dp,高度爲50dp)。我需要動態加載圖像到這個圖像視圖。如何適應圖像的寬度,並保持在android的寬高比
我希望此圖像以滿足ImageView寬度的方式縮放,但要保持高寬比(我不關心圖像的一部分因高度限制而不可見)。
我想要的與centerCrop
非常相似,但我不希望我的圖像垂直居中!
在此先感謝。
EDIT1:
這裏是我的代碼:
這是我的佈局。我想爲imageView設置圖像與background
ID。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/footer"
android:layout_alignBottom="@id/footer"
/>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="100dp">
</RelativeLayout>
注意的ImageView綁定到第二RelativeLayout的大小:
android:layout_alignTop="@+id/footer"
android:layout_alignBottom="@id/footer"
是否可以在不將drawable轉換爲位圖的情況下做到這一點?這對我的使用來說確實很慢。 –
你有什麼想法,我一直在尋找這個! +1 – instanceof