EditText now showing under ListView

為{幸葍}努か 提交于 2020-01-01 03:46:04

问题


Here is my layout:

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

What is causing my ListView to cover up my edit text?


回答1:


Perhaps try doing:

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

That way your ListView will grow to fill only unused space regardless of its own content requirements.




回答2:


You can use the weight =1 and height 0dp in Listview : As fill_parent is deprecated so use 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>


来源:https://stackoverflow.com/questions/5319965/edittext-now-showing-under-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!