微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 停止滚动CollapsingToolbarLayout,所以它不会完全崩溃

我有一个CollapsingToolbarLayout设置,并将墙纸放在那里.我想能够阻止它一塌糊涂.

我已经尝试了很高的等等,但不能弄清楚.

我怎么能让它停止崩溃第二个屏幕截图?

查看何时加载活动

所需停止点

当前停止点

解决方法

CollapsingToolbarLayout与工具栏工作非常紧密,因此折叠的高度取决于工具栏.

我可以使用这种布局解决你的问题(注意它进入正常的CoordinatorLayout / AppBarLayout安装程序,使用Fab和nestedScrollView或RecyclerView):

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

相关活动如下所示:

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

    // disable toolbar title
    getSupportActionBar().setdisplayShowTitleEnabled(false);
    ...

这是一个互动视频

原文地址:https://www.jb51.cc/android/313608.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐