CoordinatorLayout使锚定元素在向上滚动时消失 [英] CoordinatorLayout makes anchored element disappear when scrolled up
问题描述
我有一个非常尴尬的问题,我无法摆脱,而且我绝对不理解.
I have a really awkward problem that I cannot get rid of and that I absolutely do not understand.
我只是想折叠我的应用栏,并希望图像在应用栏区域中带有一些占位符元素的情况下移动. 我是从这个例子中得到的: https://github.com/saulmm/CoordinatorBehaviorExample
I simply want my app bar to collapse and an image to move with some placeholder element in the app bar area. I got this from this example: https://github.com/saulmm/CoordinatorBehaviorExample
我使用非常简单的布局:
I use a very simple layout:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout
android:minHeight="96dp"
app:layout_scrollFlags="exitUntilCollapsed|scroll">
<FrameLayout android:id="@+id/anchorPlaceHolder .../>
</CollapsingToolbarLayout>
</AppBarLayout>
<NestedScrollView ...>
<ImageView
app:layout_anchor="@id/anchorPlaceHolder
...
/>
</CoordinatorLayout>
所有操作均按预期进行-除一个重大错误外. 当滚动达到其顶端时(也就是工具栏达到其最小高度),我的图像便消失了.它是关闭"的-我不知道为什么,这是谁做的.
Everything works just as expected - EXCEPT for one massive bug. When the scrolling reaches its top end - aka the toolbar reaches its minimum height - my image simply disappears. It's "switched off" - and I don't know why and who's doing this.
我检查了层次结构,但是可见性仍然是可见的",没有关闭或什么都没有.
I inspected the hierachy, but visibility is still "VISIBLE", not switched off or anything.
任何人都可以解释这里发生了什么吗?
Can anybody explain what is going on here?
推荐答案
好的,我终于找到了这个问题的答案.
Okay, I finally found my answer to this question.
这与AppBarLayout
的其他看不见的高度有关,该高度已被包含的CollapsingToolbarLayout
修改,以防万一内部存在固定的元素并且只有那些仍然可见的情况.
It has to do with the otherwise not seen elevation of the AppBarLayout
which is modified by the contained CollapsingToolbarLayout
just in case there are pinned elements within and only those are still visible on top.
它的意思是:只要我们滚动内容,我们就会与内容内联.一旦应用栏停止(仅保留固定的元素),我们就会抬起并让其余内容滑到下面."
It's meant to say: "As long as we scroll out with the content, we are inline with the content. Once the app bar stops (only pinned elements left), we lift up and let the remaining content slide underneath."
仅当您要显示的所有元素实际上都是CollapsingToolbarLayout
的子元素时,此行为才是整洁的,但就我而言,我想锚定在CoordinatorLayout
中自由浮动的元素作为应用栏的同级元素,工具栏元素.但是,一旦我们达到固定状态,应用程序栏就会在这些自由浮动且仍锚定的元素的顶部顶部抬起,从而将其隐藏.
This behavior is neat only if all elements that you want to show are actually children of the CollapsingToolbarLayout
, but in my case I wanted to anchor elements which freely float within the CoordinatorLayout
as siblings of the app bar with some toolbar elements. But as soon as we reach the pinned state, the app bar is lifted on top of those free floating and still anchored elements - thus hiding them.
一种解决方案:给这些元素更高的标高. :-)
One solution: give those elements an even higher elevation. :-)
或:将AppBarLayout
的高度设置为0dp.
Or: set the elevation of the AppBarLayout
to 0dp.
我没有找到原因的原因很简单:所包含的CollapsingToolbarLayout
摆弄着父母的身高...;-)
The reason I did not find this is simple: the contained CollapsingToolbarLayout
fiddles with the parent's elevation... ;-)
这篇关于CoordinatorLayout使锚定元素在向上滚动时消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!