Collapsing toolbar with image, tabs and FAB

感情迁移 提交于 2019-12-05 05:46:53

问题


I'm having difficulties trying to implement the toolbar as in images below:

However, I've failed to add the Floating Action Button like shown on image. I'm using Googles design support library. Any ideas?

My current XML code:

<?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>

回答1:


I've found a solution. I thought that app:layout_anchorGravity could only reference elements like RelativeLayout's positioning attributes. But obviously, I was wrong. I've only added this code above the ViewPager in previous xml:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="10dp"
    android:layout_marginRight="10dp"
    android:src="@drawable/ic_action_add"
    app:layout_anchor="@id/collapsing_toolbar"
    app:layout_anchorGravity="bottom|right|end" />



回答2:


See my solution here. It works on API 14-23. Hope to help you



来源:https://stackoverflow.com/questions/32550361/collapsing-toolbar-with-image-tabs-and-fab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!