【问题标题】:Android studio adjust EditText on top of ListViewAndroid Studio 在 ListView 之上调整 EditText
【发布时间】:2021-09-19 15:07:23
【问题描述】:

我正在尝试将 EditText 放在 ListView 之上。使用相对布局,EditText 和 ListView 都放置在屏幕上,但文本字段与页面顶部的列表视图混合。我添加了一些空白空间,但没有工作。 如何分离edittext和listview。这是我现在的代码。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".InvoiceSearchList">

    <EditText
        android:id="@+id/invoiceSearchFilter"
        android:layout_width="match_parent"
        android:layout_height="50sp"
        android:hint="Search invoice"
        />

    <ListView
        android:id="@+id/listViewInvoiceSearchList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>


</RelativeLayout>

结果截图 EditText mixed with ListView

【问题讨论】:

  • 至少从图片上看,ListView 似乎在EditText 之上。您可以尝试更改它们的顺序。

标签: xml android-studio android-layout android-listview android-edittext


【解决方案1】:
    <RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <EditText
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:id="@+id/et1"></EditText>

  <ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/et1"></ListView>
</RelativeLayout>

只需在编辑文本上添加 ID 并将 layout_below 属性设置为 Listview 即可。

【讨论】:

    【解决方案2】:

    为列表视图添加 marginTop。

    <ListView
       android:id="@+id/id"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:layout_marginTop="60dp"
       android:layout_marginBottom="50dp"/>
    

    【讨论】:

    • 这不是正确的方法。因为您不知道编辑文本框或任何其他元素的确切高度是多少。您可以在下面查看我的答案,该答案适用于任何元素。如果它有帮助,请接受它,以便其他人受益。
    • 好的,我会检查的。感谢您的建议。
    • 欢迎。请将其标记为已回答,以便每个人都可以从中获得帮助。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多