【问题标题】:Place a Button in a EditView using TableLayout使用 TableLayout 在 EditView 中放置一个按钮
【发布时间】:2014-10-15 16:23:11
【问题描述】:

我正在尝试使用 TableLayout 中可点击的搜索按钮(没有 rightDrawable 内容)创建一个搜索文本字段。我已经在 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    |->|
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

编辑:这是现在的样子:

【问题讨论】:

  • 你的 xml 有什么问题?
  • 我希望按钮位于 EditText 内,如帖子末尾所示

标签: android button android-edittext tablelayout


【解决方案1】:

您只需将您的EditText 在您的相对布局中居中以与按钮对齐。

样本:

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

【讨论】:

  • 谢谢!有用!另外,是否可以使按钮更小(高度)?因为目前它看起来像这样:imgur.com/VrJYpN0
  • 只是为了让您知道按钮跨越文本字段的高度
  • @gedr 只需添加填充,按钮填充。
  • 但它仍然会越过文本字段(按钮位于文本字段下方的行下方)。见上图^
  • @gedr 我建议重新调整图片大小,不要填充
猜你喜欢
  • 1970-01-01
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-12
  • 1970-01-01
相关资源
最近更新 更多