我正在使用ToolBar,EditText Search和ListView,我想在向上滚动列表视图时,EditText搜索将隐藏,当向下滚动时EditText搜索显示(只有EditText显示或隐藏,而不是ToolBar)。我尝试过很多方法,但是我没有找到答案。我找到了ToolBar。
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.totoroads.android.app.ListViewBottomSheetActivity"
android:background="@color/backgroundColorGray">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="@android:color/white" />
<LinearLayout
android:id="@+id/autoCompleteEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/bg_search_map"
android:weightSum="1"
android:layout_below="@+id/toolbar">
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Enter Place Here"
android:backgroundTint="@color/white"
android:textColor="@color/white"
android:textCursorDrawable="@drawable/color_cursor"/>
<Button
android:id="@+id/gosearch"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/autoCompleteTextView"
android:layout_toRightOf="@+id/autoCompleteTextView"
android:text="TÌM" />
<Button
android:id="@+id/filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="LỌC" />
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:divider="@null"
android:dividerHeight="0dp"
android:layout_above="@+id/footer"
android:layout_below="@+id/autoCompleteEditText" />
<!-- Bottom Bar No Navigation -->
<LinearLayout
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:background="@color/white"
style="@android:style/ButtonBar">
<Button
android:id="@+id/searchMapButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/white"
android:text="@string/search_list_map" />
<Button
android:id="@+id/otherSearchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:layout_weight="1"
android:text="@string/search_nearby" />
</LinearLayout>
<!-- Ending Botton Bar -->
在ToolBar中,上面是EditText Search,
如何向上滚动ListView时隐藏EditText搜索?非常感谢!
答案 0 :(得分:0)
试试这个。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"/>
<android.support.design.widget.TabLayout
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@color/white"
app:tabIndicatorHeight="@dimen/profile_tablayout_indicator_height"
android:background="?attr/colorPrimary"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_beats"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
尝试网址:
https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling(part3)/