【问题标题】:CollapsingToolBarLayout has dual toolbarCollapsingToolBarLayout 有双工具栏
【发布时间】:2016-06-11 13:48:43
【问题描述】:

我在实施 CollapsingToolbarLayout 时遇到问题。我有这个问题:

是的,我必须将视图放置在布局中,但它会折叠在原始工具栏(或与此相关的 ActionBar)下方,如下图所示。我不知道如何解决这个问题。

感谢您的帮助。我正在使用 Android Studio 2.1.1

这是我的布局文件:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ArticleActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:id="@+id/app_bar_layout"
        android:theme="@style/AppTheme.AppBarOverlay">

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

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:id="@+id/featuredImage"
                android:src="@mipmap/ic_launcher"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                android:contentDescription="@string/article_image"/>
            <android.support.v7.widget.Toolbar
                android:id="@+id/tool_bar"
                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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_scrollFlags="scroll|enterAlways"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <WebView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/article_container" />
    </FrameLayout>

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

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

【问题讨论】:

  • 您的活动主题是否扩展了任何NoActionBar 基本主题?
  • @EricDS 是的。

标签: android android-collapsingtoolbarlayout


【解决方案1】:

我发现我哪里出错了。我在清单中遗漏了主题声明。我所要做的就是将 android:theme="AppTheme.NoActionBar" 行添加到清单中的我的活动中。

但是,这带来了两个新问题:

  1. 新的 ToolBar 滚动到视野之外(不粘在顶部。)

  2. 应该将我引导至上一个活动的 后退按钮 消失了。但是,如果我没有从研究中得到解决方案,我会将此作为一个单独的问题提出。

【讨论】:

  • 我通过从 FrameLayout 中删除行 app:layout_scrollFlags 解决了第一个问题,我将其更改为 NestedScrollView。但是,问题 #2 仍然存在。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-20
  • 1970-01-01
  • 1970-01-01
  • 2017-02-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多