删除EditText和TextView之间的空白区域

时间:2013-01-14 17:29:44

标签: android android-layout android-edittext textview

请看下面的截图。

enter image description here

我正在尝试删除EditText正下方的空白区域。没有设置任何边距或填充,这反过来让我感到困惑。这是布局XML。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<EditText
    android:id="@+id/searchText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:drawableLeft="@drawable/search_icon"
    android:ems="10"
    android:hint="@string/text_hint_search"
    android:imeOptions="actionSearch"
    android:inputType="text"
    android:lines="1"
    android:windowSoftInputMode="stateVisible" >


</EditText>

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/searchText"
    android:background="@color/textGreyColor"
    android:text="List of Items"
    android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>

有人能指导我摔倒的地方吗?

编辑:(新屏幕)

enter image description here

@Nimish Choudhary看到左右差距!

2 个答案:

答案 0 :(得分:1)

这种行为的原因是每个视图都有一些默认填充,您可以尝试

<EditText
    android:id="@+id/searchText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:drawableLeft="@drawable/ic_launcher"
    android:ems="10"
    android:hint="hint"
    android:imeOptions="actionSearch"
    android:inputType="text"
    android:lines="1"
    android:windowSoftInputMode="stateVisible" >
</EditText>

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="-5dp"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/searchText"
    android:background="@android:color/darker_gray"
    android:text="List of Items"
    android:textAppearance="?android:attr/textAppearanceMedium" />

答案 1 :(得分:0)

编辑或替换EditText视图背景上使用的9.patch drawable。 9.patch drawable中添加了填充/边距规则。 了解她的方法:http://developer.android.com/tools/help/draw9patch.html

相关问题