Android:如何删除编辑文本的底部输入部分和底部空白之间的填充

问题描述:

默认情况下,似乎在编辑文本的底部输入部分和底部空白之间存在填充。我有一个线性布局(水平线),包括一个编辑文本和一个按钮。我不能完美地将它们放在一行中,因为底部输入部分和底部边距之间的填充使编辑文本低于按钮,所以我为它们设置了相同的高度和对齐方式。Android:如何删除编辑文本的底部输入部分和底部空白之间的填充

我也试过相对布局,但也不能解决问题,这是我的布局

<RelativeLayout 
    android:id="@+id/SearchLinearLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical|center_horizontal" 
    android:layout_marginTop="10dp" > 

    <EditText 
     android:id="@+id/FilterEditText" 
     android:layout_width="fill_parent" 
     android:layout_height="38dp" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="5dp" 
     android:layout_toLeftOf="@+id/SearchButton" 
     android:gravity="center_vertical" 
     android:hint="@string/search_or_add_a_place" 
     android:imeOptions="flagNoExtractUi" 
     android:inputType="text|textNoSuggestions" 
     android:textSize="15dp" /> 

    <Button 
     android:id="@+id/SearchButton" 
     android:layout_width="38dp" 
     android:layout_height="38dp" 
     android:layout_alignParentRight="true" 
     android:background="@drawable/search_btn" 
     android:enabled="false" 
     android:gravity="center_vertical" /> 

</RelativeLayout> 
+0

然后改变button的高度。稍微增加一点。 –

+0

这是一个棘手的方法,但如果分辨率发生变化,问题可能会重新出现。 –

更改editText的背景可以解决我的问题

我更喜欢相对布局,如果你写的android:layout_toLeft或Android:layout_toRight却让他们身边正常,但即使它没有,有ALIGN_TOP或ALIGN_BOTTOM或ALIGN_BASELINE。

我和你有同样的问题,转向相对布局。对我来说更容易。

+0

谢谢,但我需要使用layout_weight,因为edittext的按钮宽度是固定的,可以根据屏幕的情况重新调整大小。 2元素应填充父宽度。 –

+0

如果我明白你想要做的事情,你可以做以下事情。添加宽度为'wrap_content'的按钮,将宽度为'fill_parent'的textview添加到Left或ToRight。这会将它们添加到旁边,textview将抓取整个屏幕,除非button.is –

+0

哦,并且您也可以在相对布局中使用layout_weight。 –