[英]Android - Using CoordinatorLayout in Activity and in Fragment
So I am using CoordinatorLayout in the Activity like.. 所以我在Activity中使用CoordinatorLayout就像..
<CoordinatorLayout>
<AppBarLayout>
<Toolbar/>
</AppBarLayout>
<FrameLayout> // For Fragments
</CoordinatorLayout>
The Toolbar
uses scroll|enterAlways
as Scrollflags
. Toolbar
使用scroll|enterAlways
作为Scrollflags
。
In one specific Fragment, I want to achieve a Parallax effect on a layout and I use CoordinatorLayout
again, but this causes the Toolbar to not behaving normally. 在一个特定的片段中,我想在布局上实现视差效果,我再次使用CoordinatorLayout
,但这会导致工具栏不能正常运行。
Here's how I use it in the Fragment
's layout : 这是我在Fragment
布局中使用它的方式:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<Toolbar/>
</CollapsingToolbarLayout>
</AppbarLayout>
<RelativeLayout/> // Contains the Fragment's content
</CoordinatorLayout>
How to achieve both effects? 如何实现这两种效果? Is it not possible because Fragment
's CoordinatorLayout
intercepts the event? 是不是因为Fragment
的CoordinatorLayout
拦截了这个事件?
So the toolbar is hidden on scroll, and I need the Search Functionalities to be hidden using parallax effect on scroll 因此工具栏隐藏在滚动上,我需要使用滚动视差效果隐藏搜索功能
I didnt try it, but this gist seems teorically a right approach, as it adds to a CoordinatorLayout a scrollingchild ability to dispatch scrolling to up too. 我没有尝试过,但这个要点似乎是一个正确的方法,因为它增加了一个CoordinatorLayout的滚动子能力也可以向上调度滚动。
Update: 更新:
Tried removing the method offsetChildToAnchor
, as it is not visible outside of the package. 尝试删除方法offsetChildToAnchor
,因为它在包外不可见。
Then found a forked gist that fixes an issue on scrolling management, and sets NestedScrollingEnabled
as true. 然后找到了一个解决滚动管理问题的分叉要点 ,并将NestedScrollingEnabled
设置为true。
Added app:layout_behavior="@string/appbar_scrolling_view_behavior"
on the nested CoordinatorLayout. 在嵌套的CoordinatorLayout上添加了app:layout_behavior="@string/appbar_scrolling_view_behavior"
。
Tested nesting two CoordinatorLayouts on an activity without fragment. 测试在没有片段的活动上嵌套两个CoordinatorLayouts。 It works. 有用。 And should work with a fragment too. 并且也应该使用片段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.