我有一个具有固定高度和宽度的ImageView(例如,宽度为100dp,高度为50dp)。我需要动态加载图像到这个ImageView中。
我希望这个图像按照一种填充ImageView宽度但保持纵横比的方式进行缩放(如果由于高度限制而导致部分图像不可见,我并不在意)。
我想要的与centerCrop非常相似,但我不希望我的图像垂直居中!
提前致谢。
编辑1:
以下是我的代码:
这是我的布局。我想为具有background id的imageView设置图像。
请注意,imageView 绑定到第二个 RelativeLayout 的大小:
我希望这个图像按照一种填充ImageView宽度但保持纵横比的方式进行缩放(如果由于高度限制而导致部分图像不可见,我并不在意)。
我想要的与centerCrop非常相似,但我不希望我的图像垂直居中!
提前致谢。
编辑1:
以下是我的代码:
这是我的布局。我想为具有background id的imageView设置图像。
<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"