如何在滚动时隐藏透明的CollapsingToolbarLayout下的内容

时间:2017-05-25 14:48:28

标签: java android android-collapsingtoolbarlayout

我有一个带有工具栏和相对布局的CollapsingToolbarLayout.CollageingToolbarLayout的contentScrim设置为transparent.what我想要的是滚动,工具栏下的每个内容都应该是不可见的。这是我到目前为止所尝试的

<?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:fancy="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.spacewek.spacewek.ProfileActivity">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="@color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlways">
            <RelativeLayout
                android:id="@+id/root_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="45dp"
                android:padding="@dimen/activity_padding"
                app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

                <com.github.siyamed.shapeimageview.RoundedImageView
                    android:id="@+id/profile_image"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_marginRight="15dp"
                    android:src="@drawable/images"
                    app:siBorderAlpha="0.01"
                    app:siBorderWidth="1dp"
                    app:siRadius="2dp"
                    />

                <TextView
                    android:id="@+id/profile_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@id/profile_image"
                    android:text="Suulisin Osman Diyaka"
                    android:textSize="15sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/current_job_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/profile_name"
                    android:layout_toRightOf="@id/profile_image"
                    android:hint="Software engineer"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/current_place_of_work"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/current_job_title"
                    android:layout_toRightOf="@id/profile_image"
                    android:text="SpaceWek"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/personal_statement"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/profile_image"
                    android:layout_marginTop="10dp"
                    android:ellipsize="none"
                    android:maxLines="2"
                    android:scrollHorizontally="false"
                    android:text="I am Ghanaian taught African trianed banana eater whose jump from tree to tree" />
            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_gravity="top"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                android:background="@color/transparent"
                android:contentInsetEnd="0dp"
                android:contentInsetLeft="0dp"
                android:contentInsetRight="0dp"
                android:contentInsetStart="0dp"
                android:elevation="0dp"
                android:minHeight="45dp"
                android:popupTheme="@android:style/ThemeOverlay.Material.Light"
                app:contentInsetEnd="0dp"
                app:contentInsetLeft="0dp"
                app:contentInsetRight="0dp"
                app:contentInsetStart="0dp"
                app:layout_collapseMode="pin"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:stateListAnimator="@null" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="-2dp"
                    android:orientation="vertical">

                    <Button
                        android:id="@+id/cancel_btn"
                        style="@style/Widget.AppCompat.Button.Borderless"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_weight="1"
                        android:drawableLeft="@drawable/ic_chevron_left_black_24dp"
                        android:gravity="left|center_vertical"
                        android:text="Back" />
                </LinearLayout>
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycular_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:paddingTop="50dp"
        android:clipToPadding="false"/>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:id="@+id/nestedContainer"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        app:layout_collapseMode="parallax"
        app:layout_collapseParallaxMultiplier="0.7">

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@id/profile_image"
            android:layout_below="@id/personal_statement"
            android:layout_marginTop="0dp"
            android:gravity="center"
            android:orientation="horizontal"
            android:tag="sticky">

            <mehdi.sakout.fancybuttons.FancyButton
                android:id="@+id/btnLinks"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:paddingBottom="6dp"
                android:paddingTop="6dp"
                fancy:fb_borderColor="#FFFFFF"
                fancy:fb_borderWidth="1dp"
                fancy:fb_defaultColor="#3b5998"
                fancy:fb_focusColor="#5577bd"
                fancy:fb_fontIconSize="25sp"
                fancy:fb_iconPaddingRight="5dp"
                fancy:fb_iconPosition="left"
                fancy:fb_iconResource="@drawable/ic_links"
                fancy:fb_radius="10dp"
                fancy:fb_text="Links"
                fancy:fb_textColor="#FFFFFF" />

            <mehdi.sakout.fancybuttons.FancyButton
                android:id="@+id/btnEdit"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:paddingBottom="6dp"
                android:paddingTop="6dp"
                fancy:fb_borderColor="#FFFFFF"
                fancy:fb_borderWidth="1dp"
                fancy:fb_defaultColor="@color/colorPrimary"
                fancy:fb_focusColor="#5577bd"
                fancy:fb_fontIconSize="25sp"
                fancy:fb_iconPaddingRight="5dp"
                fancy:fb_iconPosition="left"
                fancy:fb_iconResource="@drawable/ic_edit_black_24dp"
                fancy:fb_radius="10dp"
                fancy:fb_text="Edit"
                fancy:fb_textColor="#FFFFFF" />


        </LinearLayout>

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

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

然后在我的java文件中,我设置AppBarLayout的背景,如

Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        appBarBackground= UtilManager.blur(bitmap,context);
        appBarLayout.setBackgroundDrawable( new BitmapDrawable( context.getResources(), appBarBackground ) );

1 个答案:

答案 0 :(得分:0)

将属性app:layout_collapseMode="parallax"添加到RelativeLayout

试试这个:

..........
.................

<RelativeLayout
    android:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="45dp"
    android:padding="@dimen/activity_padding"
    app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
    app:layout_collapseMode="parallax">

...........
.................

希望这有效〜