简体   繁体   English

半展开的折叠工具栏

[英]Half expanded Collapsing toolbar

How can I create a half-expanded toolbar?如何创建半展开的工具栏? Something like that WhatsApp profile page.类似于 WhatsApp 个人资料页面。

I've tried scrollBy and scrollTo , but they don't seem to work.我试过scrollByscrollTo ,但它们似乎不起作用。

Even dispatchNestedScroll , onNesterScroll and onNestedPreScroll don't seem to work.甚至dispatchNestedScrollonNesterScrollonNestedPreScroll似乎也不起作用。

I managed to solve this problem by adapting this answer: https://stackoverflow.com/a/34920495/5369519 and using the following code:我通过调整这个答案设法解决了这个问题: https : //stackoverflow.com/a/34920495/5369519并使用以下代码:

nestedScrollView.post(() -> {
        int appBarHeight = appBar.getHeight()/2;
        nestedScrollView.startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        nestedScrollView.dispatchNestedPreScroll(0, appBarHeight, null, null);
        nestedScrollView.dispatchNestedScroll(0, 0, 0, 0, new int[]{0, -appBarHeight});
    });

This simulates scrolling halfway down.这模拟向下滚动一半。 Just using NestedScrollView.scrollTo() is not enough to trigger the scroll events for the parent.仅使用NestedScrollView.scrollTo()不足以触发父级的滚动事件。

为了创建折叠工具栏, CollapsingToolbarLayout集成了 AppBarLayout、CoordinatorLayout、Toolbar 和可滚动的内容视图,例如 RecyclerView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM