我最近注意到我在 ListView 上实现的搜索功能已停止正常工作,我无法弄清楚原因...
当用户选择搜索操作图标时,搜索框会出现在顶部并相应地调整 ListView ......至少以前是这样。
我遇到的问题是“搜索”框现在不再将 ListView 向下“推”,而是出现在它上面。
这是一个例子...
这是布局 XML...
<?xml version="1.0" encoding="utf-8"?>
<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"
android:animateLayoutChanges="true" >
<FrameLayout
android:id="@+id/search_frame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
<!-- Editext for Search -->
<EditText
android:id="@+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textVisiblePassword" />
<Button
android:id="@+id/btnClearText"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="right"
android:background="@android:color/transparent"
android:onClick="clearSearch"
android:paddingRight="10dp"
android:text="X"
android:textColor="#B3B3B3" />
</FrameLayout>
<!-- List View -->
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" />
<!--
Navigarion Drawer (Thought this might be casing the problem, but is still broken when removed)
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f9f9f9"
android:choiceMode="singleChoice"
android:divider="#919191"
android:dividerHeight="0dp" />
-->
</android.support.v4.widget.DrawerLayout>
以及显示 View 的简单 Java 代码...
/**
* Show / Hide the search box
*/
private void showSearch()
{
try
{
//in the instance there are not items...a crash will occur when searching
if(items.length > 0)
{
if(searchFrame.getVisibility() == View.VISIBLE)//hide the search bar
{
searchFrame.setVisibility(View.GONE);
resetList();
}
else//show the search bar
{
searchFrame.setVisibility(View.VISIBLE);
}
}
}
catch(Exception e)
{
Library.errorHandler("showSearch", e);
}
}
任何想法..?
谢谢
编辑:我现在发现它是 android.support.v4.widget.DrawerLayout。如果我使用 LinearLayout,它工作正常。
但是现在我不能使用抽屉导航:(
我将如何同时使用 LinearLayout 和 DrawerLayout?
最佳答案
试试这段代码
<?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" >
<EditText
android:id="@+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textVisiblePassword" />
<Button
android:id="@+id/btnClearText"
android:layout_width="46dp"
android:layout_height="30dp"
android:layout_gravity="end"
android:background="@android:color/transparent"
android:onClick="clearSearch"
android:paddingRight="1dp"
android:text="X"
android:textColor="#B3B3B3" />
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" />
</LinearLayout>
关于java - ListView 布局更改不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20116872/