CoordinatorLayout工具栏未隐藏在回收视图滚动上

时间:2017-08-02 08:45:09

标签: android android-recyclerview android-toolbar

我有一项活动

public class ResourceListActivity extends AppCompatActivity {
    private ActivityResourceListBinding mBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_resource_list);
        getWindow().setStatusBarColor(ContextCompat.getColor(getBaseContext(), R.color.colorPrimary));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setElevation(0f);
        RecommendResourceFragment fragment = RecommendResourceFragment.newInstance(mColumnCount);
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.container_main, fragment);
        fragmentTransaction.commit();
    }
}

布局文件如下:activity_resource_list.xml

    <layout 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">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="in.securelearning.lil.android.resources.view.activity.ResourceListActivity">

        <RelativeLayout
            android:id="@+id/container_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorWhite"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    </LinearLayout>
</layout>

和RecommendResourceFragment.java片段布局如下:

<layout>

    <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:orientation="vertical">


        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="4dp"
            android:background="@color/colorPrimary"
            app:layout_collapseMode="parallax"
            app:tabGravity="fill"
            app:tabMode="scrollable"/>


        <android.support.v4.view.ViewPager
            android:id="@+id/resourcePager"
            android:layout_width="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_height="match_parent"/>
    </android.support.design.widget.CoordinatorLayout>

</layout>

在下面的每个页面上,布局都是嵌入了水平标签的渲染。

<layout xmlns:app="http://schemas.android.com/apk/res-auto">

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorBackground"
        android:orientation="vertical">

        <HorizontalScrollView
            android:id="@+id/hlistview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none">

            <LinearLayout
                android:id="@+id/imageview_holder"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

            </LinearLayout>

        </HorizontalScrollView>

        <FrameLayout
            android:id="@+id/list_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="visible">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/video_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="10dp"
                android:alwaysDrawnWithCache="true"
                android:animationCache="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:drawingCacheQuality="high"
                app:layout_collapseMode="parallax"
                android:scrollbars="vertical">
            </android.support.v7.widget.RecyclerView>

            <LinearLayout
                android:id="@+id/layoutBottomProgress"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|center"
                android:gravity="center_horizontal"
                android:orientation="vertical"
                android:visibility="gone">

                <ProgressBar
                    android:id="@+id/progressBarBottom"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>

                <in.securelearning.lil.android.base.widget.TextViewCustom
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:text="Hold on !\nLoading more videos..."
                    android:textSize="16sp"
                    android:visibility="gone"/>

            </LinearLayout>

            <ProgressBar
                android:id="@+id/progress_bar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"/>

        </FrameLayout>

        <LinearLayout
            android:id="@+id/layoutNoResult"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal|center_vertical"
            android:orientation="vertical"
            android:visibility="gone">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/logo_assignment" />

            <in.securelearning.lil.android.base.widget.TextViewCustom
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="@string/string_no_results_found"
                android:textSize="20sp" />

        </LinearLayout>

    </LinearLayout>

</layout>

我已应用app:layout_behavior =&#34; @ string / appbar_scrolling_view_behavior&#34;在每个阶段,但工具栏没有隐藏。 任何建议。提前谢谢。

2 个答案:

答案 0 :(得分:0)

尝试将此行添加到工具栏

  app:layout_scrollFlags="scroll|enterAlways|snap"

答案 1 :(得分:0)

添加到工具栏

app:layout_scrollFlags="enterAlways"