CollapsingToolbarLayout 图像与缩放 [英] CollapsingToolbarLayout image with zoom

查看:79
本文介绍了CollapsingToolbarLayout 图像与缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一整天都在阅读,但没有成功.

基本上希望能够在 android.support.design.widget.CollapsingToolbarLayout 中设置 ImageView 以根据检测到的 onOffsetChanged 更改更改其高度,以便在折叠时缩小"以适合整个图像宽度并在展开时放大"以执行正常的 centerCrop 行为.

我尝试在 onOffsetChanged 中设置 ImageView 高度,但这会导致其他问题,因为 CollapsingToolbarLayout 也在重新定位它.

我在

也看到了

解决方案

您可以尝试使用 android:scaleType="matrix" 来定义折叠图像的布局.

在代码中,使用 matrix.set(imageView.getImageMatrix());

将初始 ImageMatrix 存储在 Matrix

并且根据折叠工具栏的滚动,您可以使用 matrix.postScale() 缩放图像,最后使用 imageView.setImageMatrix(matrix)<将其设置回 ImageView/代码>.这可以为您提供放大/缩小效果.

I've been reading around all day without any success on this.

Basically want to be able to set an ImageView inside a android.support.design.widget.CollapsingToolbarLayout to change it's height depending on the onOffsetChanged change detected so that it will "zoom-out" when collapsed to fit the whole image width and "zoom-in" when expanded to do normal centerCrop behavior.

I tried setting the ImageView height in the onOffsetChanged but that causes other issues assuming due to the CollapsingToolbarLayout is also repositioning it.

Sample functionality I've seen in ParallaxListView project but wish to use the CollapsingToolbarLayout.

Anyone able to give sample code (if it is possible)?

Also seen this project but again similar limitation. Other projects as well.

解决方案

You can try using android:scaleType="matrix"for the collapsing image's layout definition.

In the code, store the initial ImageMatrix in a Matrix using matrix.set(imageView.getImageMatrix());

And depending upon the scroll of collapsing toolbar, you can use matrix.postScale() to scale the image and finally set it back to the ImageView using imageView.setImageMatrix(matrix). That can give you the zoom in / out effect.

这篇关于CollapsingToolbarLayout 图像与缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆