使用表格布局在编辑视图中放置一个按钮

时间:2014-08-21 21:42:18

标签: android button android-edittext tablelayout

我正在尝试使用TableLayout中可点击的搜索按钮(没有rightDrawable stuff)创建一个搜索文本字段。我在RelativeLayout中看到过这个,但我不知道如何在TableLayout中做到这一点。这是我的activity_main.xml:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/TableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="android.tabcards.app.MainActivity" >

<TableRow
    android:id="@+id/searchTableRow"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="Enter search key" />

        <ImageButton
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_margin="30dp"
            android:src="@drawable/search"
            android:text="Button" />
    </RelativeLayout>
</TableRow>
</TableLayout>

我正在努力实现这样的目标:

    ______________________
   |Enter Text Here    |->|
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

编辑:这就是现在的样子: img

1 个答案:

答案 0 :(得分:1)

您只需将EditText置于相对布局的中心位置,即可与按钮对齐。

<强>样品:

      <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:hint="Enter search key" />
相关问题