Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有办法切换图片的时候 保持原本的缩放和移动吗? #11

Open
leeManong opened this issue Dec 12, 2023 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@leeManong
Copy link

想实现个效果,先展示的缩略图,用户双指放大后自动加载原图,能做到原图加载设置好后,还保持之前的缩放和移动吗?

@leeManong leeManong added the enhancement New feature or request label Dec 12, 2023
@panpf
Copy link
Owner

panpf commented Dec 12, 2023

这很难,因为有很多计算需要依赖 contentSize,也就是加载到内存的图片的尺寸,contentSize 改变了就必须要重置所有的缩放信息

你可以尝试将现在组件的源码复制一份,然后将 contentSize 设置为 和 containerSize 一样,看看效果

另外我想知道你是什么样的业务场景会有这样的需求

@leeManong
Copy link
Author

leeManong commented Dec 12, 2023 via email

@panpf
Copy link
Owner

panpf commented Dec 12, 2023

你的想法很难实现,你只能按我刚才说的办法试试了

@leeManong
Copy link
Author

这个代码是可以保持前后两张图的 看上去没有区别的,直接用原来的transformState替换到新的上。
有个问题就是替换后,手指去触摸缩放时会不太对。
如果能提供个setImageNoReset()就好啦。

val value = binding.imageView.zoomable.transformState.value.copy()
            Glide.with(this)
                .load("http://:www....")
                .into(object :SimpleTarget<Drawable>(){
                    override fun onResourceReady(
                        resource: Drawable,
                        transition: Transition<in Drawable>?
                    ) {
                        Glide.with(this@MainActivity).load(resource).into(binding.imageView)
//                        binding.imageView.setImageDrawable(resource)
                        lifecycleScope.launch(Dispatchers.Main) {
                            delay(100)
                            binding.imageView.zoomable._transformState.value = value
                        }
                    }

                })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants