layout_collapseParallaxMultiplier的含义

在 CollapsingToolbarLayout 布局中,其子控件有个属性 layout_collapseMode 可以控制子控件的行为,它有两个值:

app:layout_collapseMode="pin"
app:layout_collapseMode="parallax"

第一个,pin,就不用多说,这个值是将子控件固定在CollapsingToolbarLayout上,不允许折叠。

第二个,parallax,这个值表示滑动时允许子控件折叠。一般与 layout_collapseParallaxMultiplier 属性搭配使用。

 

layout_collapseParallaxMultiplier是视差系数,取值在0.0-1.0之间。 这个属性不太好懂,官方文档也没看懂,我在https://stackoverflow.com/questions/32794247/what-is-layout-collapseparallaxmultiplier-used-in-collapsingtoolbarlayout 找到了答案。

In very simple words:

When scrolling we see the following - appbar image starts hiding under the content and beyond the top edge of the screen. Parameter layout_collapseParallaxMultiplier determines what part of the image (in percent) will be hidden under the bottom content.

So, for example, setting this parameter to value 1.0 means that top boundary of appbar's image is bound to the top edge of the screen and doesn't move when scrolling. And main content is moving up the top of the image.

When the parameter is not set this corresponds to the value 0.5 and image will be overlapped above and below synchronously.

简单来说,滚动时我们会看到以下内容 - 图像开始隐藏在内容下方并超出屏幕的上边缘。参数layout_collapseParallaxMultiplier确定将在底部内容下隐藏图像的哪个部分(以百分比表示)。 因此,例如,将此参数设置为值1.0意味着appbar图像的上边界绑定到屏幕的上边缘,并且在滚动时不移动。主要内容正在向上移动到图像的顶部。 当未设置参数时,这对应于值0.5,并且图像将在上方和下方同步重叠

在滑动折叠时,将要被折叠的视图会被看做两个部分,下半部分会隐藏在内容视图的下方,上半部分会向上滑出屏幕的上边缘。

而 layout_collapseParallaxMultiplier 这个属性就设置了下半部分占整个视图的比例关系,即:

                   下半部分高度 / 视图总高度 = (0.0 - 1.0 ) 取值范围是 0.0 - 1.0 

举个例子来讲,如果设置layout_collapseParallaxMultiplier 为1.0,这意味着折叠视图的上边缘绑定到屏幕的上边缘,并且在滚动时不移动。主要内容正在向上移动到图像的顶部。

当未设置参数时,这对应于值0.5,折叠视图的上边缘向上滑动离开屏幕,同时主要内容向上滑动覆盖折叠式图的下半部分,二者滑动速度相同。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值