使用框架布局滚动工具栏无法在android上工作

时间:2017-04-25 19:14:59

标签: android scroll android-recyclerview fragment toolbar

我在使用滚动工具栏来处理我的程序时遇到了一些麻烦。现在,工具栏就像我没有实现任何滚动的东西一样。我的活动xml是这样的:

<?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:id="@+id/activity_summoner_search"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.kevin.leagueoflegendshelper.SummonerSearchActivity">


    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_Layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:id="@+id/appBarLayout">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">

                    <android.support.v7.widget.Toolbar
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/toolBar"
                        android:background="@color/colorPrimary"
                        android:elevation="4dp"
                        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                        app:layout_collapseMode="parallax">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="placeholder"
                            android:id="@+id/toolBar_Title"
                            style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
                            android:layout_gravity="start"
                            app:layout_collapseMode="parallax"
                            android:fitsSystemWindows="true"/>
                    </android.support.v7.widget.Toolbar>

                </android.support.design.widget.CollapsingToolbarLayout>

            </android.support.design.widget.AppBarLayout>



            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/frameLayout"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Search for a summoner to begin"
                    android:textSize="36dp"
                    android:paddingTop="10dp"
                    android:id="@+id/searchLabel"/>
            </FrameLayout>

        </android.support.design.widget.CoordinatorLayout>

        <android.support.design.widget.NavigationView
            android:id="@+id/nav_View"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            android:paddingTop="20dp"
            app:menu="@menu/main_drawer_layout">

        </android.support.design.widget.NavigationView>


    </android.support.v4.widget.DrawerLayout>



</RelativeLayout>

我使用具有以下布局的片段填充FrameLayout:

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

<android.support.v7.widget.RecyclerView
    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/matchRV"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    </android.support.v7.widget.RecyclerView>

我知道它可能会变得愚蠢,但我无法为我的生活似乎能够让它发挥作用。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

将属性app:layout_scrollFlags="scroll|enterAlways"添加到Toolbar

试试这个:

<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/toolBar"
    android:background="@color/colorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_scrollFlags="scroll|enterAlways"
    app:layout_collapseMode="parallax">