2011-03-23 57 views
15

我想在一行中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: enter image description here

但我不知道EditText的确切高度,所以我不能指定它ImageView这里。


当指定为ImageView高度,以填补其母公司(匹配``EditText`高):

  android:layout_height="fill_parent" 

然后我得到的图像和文本输入之间意想不到的额外保证金: enter image description here

实际上,在这种情况下,ImageView宽度等于未缩放的图像的宽度,而该图像的缩放。


这是类似于下面的图片显示,如果我指定layout_height48dp并设置adjustViewBoundsfalse

  android:layout_height="48dp" 
      android:adjustViewBounds="false" 

enter image description here


所以,这里的问题是:如何正确定义布局以缩放图像以匹配编辑条目高度,并在同一时间进行匹配宽度为ImageView将缩小到缩放图像的宽度?换句话说,如何摆脱这个额外的空间?

+0

尝试使用android:layout_marginBottom =“10dip”for imageview – 2011-03-23 11:29:23

+0

@JSE它会如何帮助?我会得到更小的图像,但周围有相同的额外空间。 – GrAnd 2011-03-23 11:50:39

+0

尝试对ImageView使用scaleType =“fitXY”和height =“fill_parent”。 – Karan 2011-03-23 15:17:08

回答

0

你也可以把重心要对线性布局集中

注意:您还应该在绘图资源,华电国际/ LDPI和MDPI不同的图像

7

这是一个LinearLayout错误。如果你看一下forceUniformHeighthere。你可以看到,以处理其供应match_parent作为当的LinearLayout设置为wrap_content高度上浆孩子的意见,假装的LinearLayout有一个绝对的高度,重新计算孩子的高度,然后重新使用先前测量处理孩子的宽度。基本上你的图像是无约束地计算高度和宽度,并获取默认宽度和高度,然后重新计算高度,但被迫使用旧宽度。您需要提供一个高度或覆盖一些视图onMeasures

相关问题