如何实现Play商店折叠工具栏布局? [英] how to implement play store Collapsing Toolbar Layout?

查看:89
本文介绍了如何实现Play商店折叠工具栏布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

*它与类似于Google Play的折叠工具栏布局不是重复的店铺

* It's not a duplicate of collapsing toolbar layout like google play store

当recyclerView向下滚动时,我想向下滚动collapsingToolbarLayout,反之亦然,如下面的.gif图像.

I want to scroll collapsingToolbarLayout down when recyclerView scrolled down and vice versa like below .gif image.

任何帮助将不胜感激.

我使用了不同的layout_scroll标志,但是它根本不起作用.

I used different layout_scroll flag but it does not work at all.

并且有xml布局:

    <?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"
      xmlns:tools="http://schemas.android.com/apk/res-auto"
      android:id="@+id/profileCoordinatorLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent">


     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:orientation="vertical"
       app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/colorPrimaryDark" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/list1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    </LinearLayout>


     <android.support.design.widget.AppBarLayout
       android:id="@+id/appBarLayout1"
       android:layout_width="match_parent"
       android:layout_height="250dp"
       android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/profileactivity_collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="@color/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:statusBarScrim="@color/colorPrimaryDark"
        app:titleEnabled="false">

        <android.support.v7.widget.Toolbar
            app:navigationIcon="@drawable/ic_menu_white"
            app:title="@string/app_name"
            android:id="@+id/toolbar1"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            app:layout_collapseMode="pin"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

    </ir.unary.zhin.CAppBar>


    <android.support.design.widget.FloatingActionButton
       android:id="@+id/fab"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="bottom"
       android:layout_margin="@dimen/fab_margin"
       app:backgroundTint="@color/colorPrimary" />

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

推荐答案

已解决:

SOLVED:

<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/main_content"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="156dp"
        android:minHeight="50dp"
        app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed|snap"
        app:titleEnabled="false">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:orientation="vertical">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:navigationIcon="@drawable/ic_menu_white"
                app:title="@string/app_name" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_gravity="bottom"
            android:background="#fff"
            android:orientation="vertical">

            <android.support.design.widget.TabLayout
                android:id="@+id/tl1"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@color/colorPrimary" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tl2"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                app:tabMode="scrollable"
                app:tabSelectedTextColor="@color/colorPrimary"
                app:tabTextColor="@color/subTitle" />
        </LinearLayout>
    </android.support.design.widget.CollapsingToolbarLayout>

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

<android.support.v7.widget.RecyclerView
    android:id="@+id/list1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/c1"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

和.gif图片:

请检查并查看它是否在所有设备上都适用?

Please check and see if it works on all devices?

这篇关于如何实现Play商店折叠工具栏布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆