1

请看下面的截图。

在此处输入图像描述

我正在尝试删除 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>

谁能指导我在哪里摔倒?

编辑:(新截图)

在此处输入图像描述

@Nimish Choudhary 看看左右两边的空隙!

4

2 回答 2

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" />

于 2013-01-14T17:36:45.770 回答
0

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

于 2013-01-14T18:06:55.097 回答