【问题标题】:EditText now showing under ListViewEditText 现在显示在 ListView 下
【发布时间】:2011-07-16 06:03:49
【问题描述】:

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical">

    <ListView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@android:id/list" />
    <EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/search" android:hint="Filter results" />

是什么导致我的ListView 掩盖了我的编辑文本?

【问题讨论】:

    标签: android listview android-edittext


    【解决方案1】:

    或许可以试试:

    <ListView
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_width="fill_parent" android:id="@android:id/list"/>
    <EditText
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:id="@+id/search"
        android:hint="Filter results"/>
    

    这样您的ListView 将增长为仅填充未使用的空间,而不管其自身的内容要求如何。

    【讨论】:

      【解决方案2】:

      您可以在 Listview 中使用 weight =1 和 height 0dp : 由于不推荐使用 fill_parent,因此请使用 match_parent。

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">
      
          <ListView
              android:id="@android:id/list"
              android:layout_width="match_parent"
              android:layout_height="0dp"
              android:layout_weight="1"/>
      
          <EditText
              android:id="@+id/search"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:hint="Filter results" />
      </LinearLayout>
      

      【讨论】:

        猜你喜欢
        • 2016-04-18
        • 2011-03-22
        • 2023-03-03
        • 1970-01-01
        • 2015-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-13
        相关资源
        最近更新 更多