【发布时间】:2015-07-08 19:26:11
【问题描述】:
我正在开发显示图像的应用程序,我需要创建一个以 1:1 纵横比显示大图像的视图。
首先,我有分辨率为72x72 的缩略图。我已将它们放在ImageView 中,但即使我添加参数android:width="fill_parent" 和android:height="wrap_content",图像也不会是ImageView 的大小,而是仅居中在中间。
我尝试添加参数android:scaleType="centerCrop",它可以很好地水平调整图像大小,但高度保持不变。
我如何设置我的ImageView,使其在所有设备上的宽度与父视图一样高,也应与高度一样。
我可以以编程方式执行此操作,但我需要能够在 XML 中执行此操作。
我的 XML 文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
// The ImageView I am talking about above
<ImageView
android:id="@+id/invitation_imageview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:scaleType="centerCrop"
android:src="@drawable/face_woman_smile" />
<ImageView
android:id="@+id/invitation_avatar_view_1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:src="@drawable/face_woman_smile"
android:scaleType="center"
android:layout_margin="1dp" />
</LinearLayout>
【问题讨论】:
-
将图像设置为
android:background,它们将被拉伸以匹配父尺寸。
标签: android image android-layout android-xml scaletype