2011-11-29 101 views
0

默認情況下,似乎在編輯文本的底部輸入部分和底部空白之間存在填充。我有一個線性佈局(水平線),包括一個編輯文本和一個按鈕。我不能完美地將它們放在一行中,因爲底部輸入部分和底部邊距之間的填充使編輯文本低於按鈕,所以我爲它們設置了相同的高度和對齊方式。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

這是一個棘手的方法,但如果分辨率發生變化,問題可能會重新出現。 –

回答

3

更改editText的背景可以解決我的問題

1

我更喜歡相對佈局,如果你寫的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。 –

相關問題