android - 具有线性布局的 AppBarLayout

标签 android android-layout android-collapsingtoolbarlayout android-appbarlayout

我有以下风格

<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/AppTheme.AppBarOverlay">

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

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="@dimen/app_bar_height"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/profile_girl"
            app:layout_collapseMode="parallax"
            tools:ignore="ContentDescription" />

        <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/AppTheme.PopupOverlay" />

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

    <RelativeLayout
        android:id="@+id/layout_profile_info"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@android:color/white"
        android:paddingBottom="16dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="32dp"
        app:layout_collapseMode="parallax">

        <TextView
            android:id="@+id/profile_username_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:text="Real Name"
            android:textAppearance="@style/TextAppearance.AppCompat.Title"
            android:textColor="?android:attr/textColorPrimaryInverse" />

        <LinearLayout
            android:id="@+id/profile_count_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profile_username_text"
            android:orientation="horizontal"
            android:paddingBottom="8dp"
            android:paddingTop="8dp">

            <TextView
                android:id="@+id/posts_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="4dp"
                android:text="45"
                android:textColor="?android:attr/textColorPrimaryInverse"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/posts_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:text="POSTS"
                android:textAppearance="@style/TextAppearance.AppCompat.Caption"
                android:textColor="?android:attr/textColorSecondaryInverse" />

            <TextView
                android:id="@+id/following_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="4dp"
                android:text="45"
                android:textColor="?android:attr/textColorPrimaryInverse"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/following_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:text="FOLLOWING"
                android:textAppearance="@style/TextAppearance.AppCompat.Caption"
                android:textColor="?android:attr/textColorSecondaryInverse" />

            <TextView
                android:id="@+id/followers_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="4dp"
                android:text="45"
                android:textColor="?android:attr/textColorPrimaryInverse"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/followers_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="FOLLOWERS"
                android:textAppearance="@style/TextAppearance.AppCompat.Caption"
                android:textColor="?android:attr/textColorPrimaryInverse" />

        </LinearLayout>

        <TextView
            android:id="@+id/profile_desc_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profile_count_layout"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:text="One must hear the karma in order to develop the doer of unbiased joy."
            android:textColor="?android:attr/textColorSecondaryInverse" />

    </RelativeLayout>

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

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

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

<de.hdodenhof.circleimageview.CircleImageView
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_gravity="center"
    android:layout_margin="16dp"
    android:src="@drawable/profile_avatar"
    app:civ_border_color="#FFFFFFFF"
    app:civ_border_width="2dp"
    app:layout_anchor="@id/toolbar_layout"
    app:layout_anchorGravity="bottom|left" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_person_add_white_24dp"
    app:layout_anchor="@id/toolbar_layout"
    app:layout_anchorGravity="bottom|end" />

此布局生成

enter image description here
我想获得以下行为:

当向上滚动时,相对布局在 CollapsingToolbarLayout 下,最后我必须有带 TabLayout 和圆形配置文件图标的工具栏,并且 FAB 必须消失。

如果我将 FAB 隐藏和显示操作锚定到 AppBarLayout,它会完美运行,但是当我将它锚定到 CollapsingToolbarLayout 时,它不起作用。另外,当我向上滚动时,如何将 Relative Layout 推到 CollapsingToolbar 下。

我试图将 Relative Layout 放在 CollapsingToolbar 中,但没有成功。

最佳答案

为相对布局启用嵌套滚动

RelativeLayout ref;
NestedScrollingChildHelper mNestedScrollingChildHelper = new NestedScrollingChildHelper(ref);
mNestedScrollingChildHelper.setNestedScrollingEnabled(true);

关于android - 具有线性布局的 AppBarLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35186515/

相关文章:

android - 在 CollapsingToolBar 布局 Android 中设置标题和副标题

java - Android Room 在 'incoming foreign key list' 中获取 'embedded entity' 中的元素计数?

android-layout - 为什么我的 Android setOnItemClickListener 不起作用?

java - 当屏幕方向改变时,如何防止布局被重置?

android - 为什么 0dp 被认为是性能增强?

android - CoordinatorLayout 内的 ViewPager 内的 RecyclerView 内的 NestedScrollView 不可滚动

android - 需要在 Android Studio 中使用 Team Foundation 客户端可能的替代方案/解决方法?

android - 导航组件 : IllegalStateException Fragment not associated with a fragment manager

java - 我如何在下面的上下文中干燥我的代码(android)

android - 使用 tablayout 折叠工具栏