[英]Unable to hide Toolbar while scrolling RecyclerView, possible cause?
[英]toolbar is not hiding automatically need to push manually to hide while scrolling in recyclerview
我的應用程序包含一個帶有工具欄,線性布局和Tabllayout的片段。 我已啟用工具欄的滾動標記。 現在,當我嘗試在tablayout中的recyclerview中滾動時,工具欄並沒有阻礙。 當我手動按下TabLayout時,它開始移動並能夠隱藏或顯示。 以下是我正在使用的布局。 怎么了
主要布局:
<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/coordinatorLayout"
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.ActionBar"
android:id="@+id/app">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:background="@color/textcolor"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways">
<Button
android:id="@+id/back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="start"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:background="@drawable/backblack" />
</android.support.v7.widget.Toolbar>
<LinearLayout
android:id="@+id/layloc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:orientation="horizontal"
android:weightSum="1"
android:padding="5dp"
android:background="@drawable/border"
android:visibility="gone">
<TextView
android:id="@+id/locationname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableStart="@drawable/location"
android:drawableLeft="@drawable/location"
android:drawablePadding="3dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:textColor="@color/cblack"
android:text="fetching current location"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium.Inverse"/>
<TextView
android:id="@+id/change"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Change"
android:drawablePadding="3dp"
android:textColor="@color/cblack"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>
</LinearLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layloc"
android:background="@color/textcolor"
app:tabTextColor="@color/black"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
app:tabIndicatorHeight="2dp" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
片段布局:
<android.support.design.widget.CoordinatorLayout
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"
android:background="@color/textcolor"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/mainexplore">
<android.support.v7.widget.RecyclerView
android:id="@+id/lists"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@drawable/list_divider"
android:dividerHeight="1px"
android:scrollbars="none"
android:visibility="gone"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<TextView
android:id="@+id/emptyElement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/nofoodfound"
android:textColor="@color/button"
android:visibility="gone"/>
</android.support.design.widget.CoordinatorLayout>
我嘗試使用不同的滾動標志,但是問題是相同的。 我在SO中已經看到了示例和一些與此類似的問題,但是它們都沒有回答我的查詢。 工具欄可以隱藏,但需要手動按下。 布局有什么問題。 此布局中缺少什么。
您需要從appBarLayout中刪除按鈕視圖。 檢查我的。
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinator_layout"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:elevation="5dp"
android:theme="@style/ToolbarTheme"
app:layout_scrollFlags="scroll|enterAlways"
app:titleTextAppearance="@style/Toolbar.TitleText"
/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/textcolor"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|enterAlways">
<Button
android:id="@+id/back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="start"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/backblack" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.