滚动时为什么我的Actionbar没有向上移动?

时间:2015-10-05 06:14:11

标签: android android-fragments android-actionbar android-toolbar android-recyclerview

我有一个带抽屉布局的活动,工具栏包含如下:

<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.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.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<include
    android:id="@+id/tool_bar"
    layout="@layout/tool_bar"
    >
</include>
<!-- The main content view -->
<FrameLayout
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<!-- The navigation drawer list-->
<android.support.v7.widget.RecyclerView
    android:id="@+id/RecyclerView"
    android:layout_width="280dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:background="#ffffff"
    android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.DrawerLayout>

工具栏如下所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/background_floating_material_dark"
android:elevation="4dp"
android:paddingTop="1dp"
app:layout_scrollFlags="scroll|enterAlways">
</android.support.v7.widget.Toolbar>

对于此活动,我继续添加/替换片段@ id / frame_container

现在我的情况是我有一个包含2个标签的片段,这些标签又将回收者视图提供给视图寻呼机: 我在java中设置如下:

TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tab_layout2);

    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    viewPager = (ViewPager) rootView.findViewById(R.id.pager2);
    adapter = new MyFragmentAdapter(
            getFragmentManager(), 2);
    viewPager.setAdapter(adapter);
    tabLayout.setupWithViewPager(viewPager);

此片段的布局:

<RelativeLayout ...
 <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:background="?attr/colorPrimary"
        android:elevation="6dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager
    android:layout_marginTop="@dimen/abc_action_bar_stacked_max_height"
    android:id="@+id/pager2"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/tab_layout"
    />
</RelativeLayout>

视图寻呼机中的片段具有回收者视图。:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/listViewPO"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        android:layout_marginBottom="2px">

    </android.support.v7.widget.RecyclerView>
</RelativeLayout>

问题是当我尝试滚动时,操作栏没有隐藏。我无法弄清楚这个问题。我花了几天时间。请帮忙!

0 个答案:

没有答案