我想在一行中EditText
放置与ImageView
左侧。但我无法正确缩放图像以匹配文本输入的高度。ImageView的:adjustViewBounds不layout_height = “FILL_PARENT” 工作?
布局很简单:
<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"
然后我得到最接近的视图我neede d:
但我不知道EditText
的确切高度,所以我不能指定它ImageView
这里。
当指定为ImageView
高度,以填补其母公司(匹配``EditText`高):
android:layout_height="fill_parent"
然后我得到的图像和文本输入之间意想不到的额外保证金:
实际上,在这种情况下,ImageView
宽度等于未缩放的图像的宽度,而该图像的缩放。
这是类似于下面的图片显示,如果我指定layout_height
到48dp
并设置adjustViewBounds
到false
:
android:layout_height="48dp"
android:adjustViewBounds="false"
所以,这里的问题是:如何正确定义布局以缩放图像以匹配编辑条目高度,并在同一时间进行匹配宽度为ImageView
将缩小到缩放图像的宽度?换句话说,如何摆脱这个额外的空间?
尝试使用android:layout_marginBottom =“10dip”for imageview – 2011-03-23 11:29:23
@JSE它会如何帮助?我会得到更小的图像,但周围有相同的额外空间。 – GrAnd 2011-03-23 11:50:39
尝试对ImageView使用scaleType =“fitXY”和height =“fill_parent”。 – Karan 2011-03-23 15:17:08