标签: android-collapsingtoolbarlayout

显示片段时停止滚动CollapsingToolbarLayout

我有一个ViewPager内部Activity显示两个Fragments.

活动有a TabLayout和a CollapsingToolbarLayout.所述CollapsingToolbarLayout嵌套内的AppBarLayoutImageView以产生视差效应.该TabLayout是外AppBarLayoutLinearLayout使用ViewPager.再有一个FrameLayout,以及展现另一个FragmentViewPager当用户点击一个按钮来表明Fragment.

问题是,当你滚动RecyclerView里面的Fragment是覆盖在上面ViewPagerActivity还滚动并执行视差效果.从本质上讲,它同时滚动RecyclerView内部Fragment和内部的内容ViewPager.

当用户看到时,有没有办法停止滚动CollapsingToolbarLayout并且仅滚动覆盖内容?FragmentFragment

这就是我的XML Hierarchy的样子:

<android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.AppBarLayout>

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

        <ImageView
            app:layout_collapseMode="parallax"/>

        <android.support.v7.widget.Toolbar />

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

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

<LinearLayout
    app:layout_behavior="@string/appbar_scrolling_view_behavior" >

    <android.support.design.widget.TabLayout />
    <!-- Two fragments inside ViewPager each containing a RecyclerView …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-viewpager android-collapsingtoolbarlayout

2
推荐指数
1
解决办法
4940
查看次数

layout_scrollFlags不适用于CollapsingToolbarLayout之外的视图

我想滚动用户说明,但layout_scrollFlags ="滚动"不适用于RelativeLayout.ViewPager有2个片段,里面有SwipeRefreshLayout和RecyclerView.如何在CollapsingToolbar exitUntilCollapsed时滚出描述?

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

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/user_background"
            android:layout_width="match_parent"
            android:layout_height="192dp"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_marginBottom="@dimen/keyline_1">

            <ImageView
                android:id="@+id/avatar"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginLeft="@dimen/keyline_1"
                android:layout_marginStart="@dimen/keyline_1" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/keyline_1"
                android:layout_marginStart="@dimen/keyline_1"
                android:layout_toEndOf="@id/avatar"
                android:layout_toRightOf="@id/avatar"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/full_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body2" />

                <TextView
                    android:id="@+id/screen_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

            </LinearLayout>

        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

    <RelativeLayout
        android:id="@+id/information"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll">

        <TextView
            android:id="@+id/bio"
            android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android-design-library androiddesignsupport android-collapsingtoolbarlayout android-appbarlayout android-tablayout

2
推荐指数
1
解决办法
6249
查看次数

折叠工具栏与图像,选项卡和FAB

我在尝试实现工具栏时遇到了困难,如下图所示:

在此输入图像描述

但是,我无法添加如图所示的浮动操作按钮.我正在使用谷歌设计支持库.有任何想法吗?

我目前的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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="250dp"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7">

                <ImageView
                    android:id="@+id/imgBackdrop"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#20000000" />

            </FrameLayout>


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                style="@style/Widget.PinList.ActionBar.Transparent"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin" />

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

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

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                style="@style/PinListTabLayout"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                app:layout_collapseMode="pin" />

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

xml android toolbar android-support-library android-collapsingtoolbarlayout

2
推荐指数
1
解决办法
7535
查看次数

CollapsingToolbarLayout + TabLayout,奇怪的工具栏标题边距

我有一个srange工具栏标题行为,我怀疑是有效的.

崩溃了:

折叠的工具栏

延长:

扩展工具栏

最奇怪的部分是

应用:titleMarginTop

对标题的放置没有任何影响.

这是我的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/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.m360learning.app.activity.UserDetailsActivity">


    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:background="@drawable/background_navigation_drawer"
                app:layout_collapseMode="parallax">
                <ImageView
                    android:id="@+id/header"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerInside" />

            </RelativeLayout>


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:gravity="top"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

                 />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="bottom"
                app:tabIndicatorColor="@color/colorAccent" />

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

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

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.谢谢

---编辑:如果我将工具栏大小设置为"actionbarsize" …

android android-collapsingtoolbarlayout

2
推荐指数
2
解决办法
4821
查看次数


如何确定ImageView在CollapsingToolbar中是否可见?

我有一个折叠的工具栏布局,如下所示:

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/expanded_toolbar_height"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

       <include layout="@layout/circle_image_view"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </android.support.design.widget.CollapsingToolbarLayout>
Run Code Online (Sandbox Code Playgroud)

这里circle_image_view

<com.example.ui.CircularParseImageView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/iv_circular_backdrop"
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:layout_gravity="center"
    android:fitsSystemWindows="true"
    android:scaleType="centerCrop"
    android:transitionName="@string/transition_pic"
    app:layout_collapseMode="parallax" />
Run Code Online (Sandbox Code Playgroud)

这只是带有圆形蒙版的标准图像视图。展开折叠式工具栏时,圆形的“图像”视图将可见,并显示如下:

展开图

折叠后,图像视图不再可见,如下所示:

收合检视

但是,即使在折叠状态下,图像视图的可见性似乎仍设置为“可见”。当用户按下“后退”按钮时,我需要确定图像是否可见以执行共享元素过渡动画。 如何确定图像在折叠工具栏中当前是否可见?

我尝试过的

getVisibility() 保持不变

isOpaque() 保持不变

getImageAlpha() 保持不变

android android-imageview android-collapsingtoolbarlayout

2
推荐指数
1
解决办法
589
查看次数

带有 CoordinatorLayout 的 NestedScrollView 中的 Recycler 视图

下面是代码片段,有人可以帮我吗?我的折叠工具栏根本没有折叠。预期行为是:当我向上滚动时,工具栏应该从168dp到折叠56dp。但它根本没有崩溃。提前致谢。

<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:background="@color/one_primaryColor"
    android:fitsSystemWindows="true">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            app:layout_collapseMode="pin">

            <ImageView
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:contentDescription="@string/app_name"

            app:layout_collapseMode="parallax"
            android:src="@drawable/logo" />

        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v7.widget.RecyclerView...
Run Code Online (Sandbox Code Playgroud)

android material-design android-toolbar android-collapsingtoolbarlayout

2
推荐指数
1
解决办法
3257
查看次数

获取折叠工具栏布局的标题文本视图

我有一个collapsingToolbarLayout,我需要对 title 做一些额外的设置TextView

问题:如何获得对该 TextView 的引用?

在此处输入图片说明

<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/tools"
    android:id="@+id/review_coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.stack.overflow.reviewmaschine.ReviewMaschineActivity"
    tools:ignore="MergeRootFrame">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/detail_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

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

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

    <com.mego.smscloud.reviewmaschine.SaveFloatingActionButton
        android:id="@+id/review_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:backgroundTint="@color/colorPrimary"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_floppy_white_48dp"
        app:borderWidth="0dp"
        app:elevation="@dimen/fab_elevation"
        app:rippleColor="#00ffff"/>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

编辑: 简单地将 a 添加TextView到 theToolbar并不能将其集成到与CollapsingToolbarLayouttitle相同的行为中 在此处输入图片说明

android toolbar textview android-collapsingtoolbarlayout

2
推荐指数
1
解决办法
3297
查看次数

使用CollapsingToolbarLayout滚动PreferenceFragment

我试图建立PreferenceFragmentCollapsingToolbarLayout.问题是元素太多PreferenceFragment而且没有显示.似乎NestedScrollView没有使用这些片段.这里的解决方案对我不起作用,因为我不能出于其他原因使用compat库.我该如何解决这个问题?

码:

<android.support.v4.widget.NestedScrollView 
 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:layout_width="match_parent"
 android:layout_height="match_parent"
 android:fillViewport="true"
 app:layout_behavior="@string/appbar_scrolling_view_behavior"
 tools:showIn="@layout/activity_user_profile">

  <FrameLayout
    android:id="@+id/user_profile_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

android preferencefragment android-collapsingtoolbarlayout android-nestedscrollview

2
推荐指数
1
解决办法
579
查看次数

如何使用折叠工具栏在协调器布局中固定工具栏?

我试图使工具栏始终显示在此布局中,而不是仅在它完全滚动出来时才出现。我在折叠工具栏中有一个图像,当完全滚动时需要隐藏它。

这是我尝试过的..关于如何实现它的任何意见?

        <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/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".activities.Event_details">


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/topLayout"
        app:layout_anchorGravity="top"
        android:layout_gravity="top" >
        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:id="@+id/toolbar"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/toolbar_height">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/colorWhite"
                    android:id="@+id/toolbarTitle"
                    android:layout_centerVertical="true"
                    android:layout_marginEnd="?android:attr/actionBarSize"
                    android:textStyle="bold"
                    android:textSize="@dimen/page_innerheader_titletxt"
                    android:text="@string/app_name"/>

                <TextView
                    android:id="@+id/save_toolbar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/save"
                    android:textColor="@color/colorYellow"
                    android:layout_centerVertical="true"
                    android:textSize="@dimen/textsize16"
                    android:layout_toStartOf="@id/toolbarButton"
                    android:layout_marginEnd="15dp"/>

                <Button
                    android:id="@+id/toolbarButton"
                    android:layout_width="60dp"
                    android:layout_height="30dp"
                    android:text="@string/done"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"
                    android:textColor="@color/colorPrimary"
                    android:background="@drawable/rect_yellow"
                    android:layout_marginEnd="10dp"
                    />
            </RelativeLayout>


        </android.support.v7.widget.Toolbar>

           </RelativeLayout>
        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:elevation="6dp"
            app:layout_anchor="@id/topLayout"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:fitsSystemWindows="true">


            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleMarginEnd="64dp">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-coordinatorlayout android-collapsingtoolbarlayout

2
推荐指数
1
解决办法
2513
查看次数