在CollapsingToolbarLayout上停止滚动,使其不会完全崩溃

Big*_*dad 18 android android-design-library android-collapsingtoolbarlayout

我有一个CollapsingToolbarLayout设置,我在那里放置一个壁纸.我希望能够阻止它一直崩溃.

我已经尝试了minheight和许多其他的东西,但无法搞清楚.

如何让它停止折叠到第二个屏幕截图?

查看加载活动的时间

加载视图

期望的停止点

期望的停止点

目前的停止点

目前的停止点

efe*_*ney 13

CollapsingToolbarLayout与此非常接近,Toolbar因此折叠高度取决于工具栏.

我能够使用这种布局解决您的问题(注意它进入正常CoordinatorLayout/ AppBarLayout设置,使用Fab和a NestedScrollViewRecyclerView):

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:layout_scrollFlags="scroll|exitUntilCollapsed"
    app:statusBarScrim="?attr/colorPrimaryDark"
    app:contentScrim="@android:color/transparent"
    app:titleEnabled="false"
    >
    <!-- There isnt a contentSCrim attribute so the toolbar is transparent after being
         collapsed
         Disabled the title also as you wont be needing it -->

    <ImageView
        android:id="@+id/image_v"
        android:layout_width="match_parent"
        android:layout_height="360dp"
        android:layout_gravity="center"
        android:scaleType="centerCrop"
        android:src="@drawable/md2"
        android:fitsSystemWindows="true"
        app:layout_collapseMode="parallax"
        tools:ignore="ContentDescription"
        />
        <!-- Normal Imageview. Nothing interesting -->

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="168dp"
        app:layout_collapseMode="pin"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        />
        <!-- The toolbar is styled normally. However we disable the title also in code.
        Toolbar height is the main component that determines the collapsed height -->

    <TextView
        android:text="@string/app_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="?attr/colorPrimaryDark"
        android:paddingLeft="72dp"
        android:paddingRight="0dp"
        android:paddingBottom="24dp"
        android:paddingTop="24dp"
        android:textColor="@android:color/white"
        android:textAppearance="@style/TextAppearance.AppCompat.Headline"
        />
        <!-- The title textView -->

</android.support.design.widget.CollapsingToolbarLayout>
Run Code Online (Sandbox Code Playgroud)

相关活动如下所示:

    ...
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Disable toolbar title
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    ...
Run Code Online (Sandbox Code Playgroud)

这是一段互动视频

在此输入图像描述


CI *_*pps 11

我遇到了同样的问题.

首先,我只是设置工具栏的高度,如前面的答案所述,它的工作原理.

但这导致了另一个问题.工具栏视图会触摸触摸事件,因此我的折叠视图(即MapView)不会将任何触摸事件与工具栏重叠.

最后,我的解决方案是从CollapsingToolbarLayout中删除工具栏.在我的情况下它是好的,因为我只使用它来限制折叠.并在onCreateView中设置最小折叠高度,如下所示:

CollapsingToolbarLayout layoutCollapsing = (CollapsingToolbarLayout) rootView.findViewById(R.id.layoutCollapsing);
layoutCollapsing.setMinimumHeight(120);
Run Code Online (Sandbox Code Playgroud)

  • 好主意!您可以在布局文件中设置最小高度而不是代码. (2认同)