我试图将其放在单行中EditText
与ImageView
在左侧。但我无法正确缩放图像以匹配文本输入的高度。
布局很简单:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:background="#f00"
android:src="@drawable/icon" />
<EditText
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
(我用红色突出显示图像背景,以查看 ImageView 分配的实际空间)
如果我指定确切的高度ImageView
:
android:layout_height="48dp"
then I get the closest view what I needed:
但不知道具体高度EditText
,所以我无法指定它ImageView
here.
当高度为ImageView
指定填充其父级(以匹配“EditText”高度):
android:layout_height="fill_parent"
then I get unexpected extra margin between the image and text entry:
事实上,在这种情况下ImageView
宽度等于未缩放的图像宽度,而图像已缩放。
如果我指定的话,它类似于下图所示layout_height
to 48dp
并设置adjustViewBounds
to false
:
android:layout_height="48dp"
android:adjustViewBounds="false"
因此,这里的问题是:如何正确定义布局以缩放图像以匹配编辑条目高度,同时宽度为ImageView
缩小到缩放图像宽度?换句话说,如何摆脱这个额外的空间?