【问题标题】:Issue with Collapsing Toolbar折叠工具栏的问题
【发布时间】:2018-07-16 15:17:45
【问题描述】:

在 CollapsingToolbarLayout 中向上滚动时,使“带有标题文本的工具栏”不折叠时遇到问题。

我已经尝试了一些调整,但它不起作用。可能是我的布局有问题。

以下是我想要实现的目标。

但是当我滚动到顶部时,Toolbar 也会折叠,并且 tabBar 也会在里面滚动,并且变得不可见。以下是我现在拥有的。

这是我的布局代码

<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/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="match_parent"
        app:titleEnabled="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <com.oxymob.oxygen.customviews.MemberView
            android:id="@+id/view_member"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="?actionBarSize"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            app:layout_collapseMode="pin">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                style="@style/AppTheme.ToolbarStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                app:theme="@style/AppTheme.ActionBarTheme" />

            <include
                layout="@layout/include_progress"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom" />
        </FrameLayout>
    </android.support.design.widget.CollapsingToolbarLayout>

    <com.ogaclejapan.smarttablayout.SmartTabLayout
        android:id="@+id/detail_tabs"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:background="@color/colorPrimary"
        android:clipToPadding="false"
        android:paddingLeft="4dp"
        android:paddingRight="4dp"
        app:stl_defaultTabTextColor="@android:color/white"
        app:stl_defaultTabTextHorizontalPadding="18dp"
        app:stl_dividerColor="@color/transparent"
        app:stl_dividerThickness="0dp"
        app:stl_indicatorColor="@color/black_20"
        app:stl_indicatorCornerRadius="18dp"
        app:stl_indicatorGravity="center"
        app:stl_indicatorInterpolation="smart"
        app:stl_indicatorThickness="36dp"
        app:stl_underlineColor="@color/transparent"
        app:stl_underlineThickness="0dp" />

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

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

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

依赖关系

dependencies {
    cimplementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:cardview-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'

}

【问题讨论】:

  • 您可以尝试将折叠工具栏的高度设置为“wrap_content”,并在协调器布局中添加“title_enabled”=true
  • 嗨@AnkitMehta 我刚刚尝试过,它仍然是一样的,工具栏崩溃。感谢帮助

标签: android android-coordinatorlayout android-collapsingtoolbarlayout


【解决方案1】:

在您的 xml 中,您的父级必须是协调器布局,而您的 AppBarLayout 需要一种特定类型的主题,即

android:theme="@style/AppTheme.AppBarOverlay"

。我强烈建议您按照下一个教程来归档您所加速的行为。

https://www.coderefer.com/collapsing-toolbar-layout-android/

【讨论】:

  • 父布局还是一个coordinatorLayout。谢谢,但我已经按照教程进行操作了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
相关资源
最近更新 更多