1

我有一种不幸的感觉,这只是 Android 的一个错误,因为 DrawerLayout 仍然相对较新。

基本上我拥有的是一个 ListView,上面设置了一个 ArrayAdapter。我以前执行 textfilter 搜索没有任何问题。但后来我决定在布局中实现一个 DrawerLayout。一旦添加了抽屉,文本过滤就会中断。

以前,软件键盘会弹出,您将开始输入(您的输入覆盖在屏幕上),列表将按该字符串过滤。

使用抽屉布局,键盘会弹出,但在键入内容时没有任何反应。

我很肯定抽屉布局在某种程度上对此负责,因为一旦我删除了布局代码,搜索功能就会再次开始工作。

作为参考,这是我的 XML:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/header_container">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:gravity="center_vertical"
            android:id="@+id/header_text" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@id/header_text"
            android:layout_alignBottom="@id/header_text"
            android:layout_alignParentRight="true"
            android:id="@+id/searchbutton"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_menu_search"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/header_text"
            android:layout_toLeftOf="@id/searchbutton"
            android:layout_alignParentTop="true"
            android:gravity="center"
            android:visibility="visible"
            android:id="@+id/headerClassField"/>
        <ListView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/header_text"
            android:fastScrollEnabled="true"
            android:id="@+id/spell_list_view" />

    </RelativeLayout>

    <include layout="@layout/drawer_spell_list"/>
</android.support.v4.widget.DrawerLayout>

以及其中包含的抽屉代码:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="240dp"
              android:layout_gravity="left"
              android:background="@color/midnight_blue"
              android:layout_height="match_parent">

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="3dp"
        android:orientation="horizontal">
        <ImageView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/star"/>
        <TextView
            android:id="@+id/drawer_metamagic_link"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:textSize="16sp"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical"
            android:text="@string/drawer_metamagic"/>
    </LinearLayout>

    <LinearLayout
        style="@style/drawer_border"/>

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="3dp"
        android:orientation="horizontal">
        <ImageView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/inward_arrows"/>
        <TextView
            android:id="@+id/drawer_longclick_link"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:textSize="16sp"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical"
            android:text="@string/drawer_longclick"/>
    </LinearLayout>



    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="32sp"
        android:text="..."/>

    <include layout="@layout/drawer_main"/>

</LinearLayout>

抽屉工作完美,但包含抽屉时搜索不会。任何帮助将不胜感激!

编辑:有趣的是,如果我使用 SlidingPanelLayout 而不是 DrawerLayout,过滤器不会中断。这可能需要成为我的解决方法。

4

0 回答 0