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

菜单展开的时候,执行notifyDatasetChange,状态会错位 #39

Open
yuluowusheng opened this issue Jan 13, 2024 · 3 comments
Open

Comments

@yuluowusheng
Copy link

比如从现在RecycleView中,第5条rightMenu处于open状态,执行notifyDatasetChange,这个时候,第5条的状态会变为初始关闭状态,而第1条或2条的rightMenu处于open状态,能修复一下吗?

原因可能是RecycleView复用导致的

@yuluowusheng
Copy link
Author

yuluowusheng commented Jan 13, 2024

我通过记录位置的方式修正:notifyDataSetChanged()时,原始打开位置的左滑菜单默认隐藏,我记录状态,onbindView时再打开,有一个闪现的过程,体验十分不好

原因是:onBindView时直接调用openmenu无效,必须等到onMesuer,onlayout结束之后才行,我现在onBindView时是这样做的
//binding.swipeLayout.openRightMenu(false) 此时menu为空,不会执行
binding.swipeLayout.post { //必须等到绘制完成才行,才会生效,但是这样就会等待和闪现
binding.swipeLayout.openRightMenu(false)
}

大佬救我

@aitsuki
Copy link
Owner

aitsuki commented Jan 13, 2024

错位问题确实是RecyclerView复用导致的,开启和关闭需要自己记录。
onBindViewHolder没法开启菜单确实是设计缺陷,这控件就是奇怪的代码堆起来的,我自己都改不动了……

不过我倒是有个办法可以暂时解决你的问题,在onCreateViewHolder的时候主动测量一次就好了,虽然很丑但是能解决问题,例如:

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
    val swipeLayout = LayoutInflater.from(parent.context).inflate(R.layout.item_xxx, parent, false)
    swipeLayout.measure(0, 0)
    return object: ViewHolder(swipeLayout){}
}

@yuluowusheng
Copy link
Author

感谢大佬

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

No branches or pull requests

2 participants