在通过导航组件添加到动作的动画完成之前,防止单击视图 [英] Prevent views from being clicked until animation added to action via navigation component completes

查看:58
本文介绍了在通过导航组件添加到动作的动画完成之前,防止单击视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出2个片段 A B A 移到 B (所以 A->; B ),已添加带有输入动画的导航组件操作.如何防止输入动画运行时片段 B 中的视图可单击?我发现了这个问题如何将侦听器添加到android导航体系结构组件动作动画中,但不幸的是没有答案.

Given 2 Fragments A and B, A moves to B (so A -> B), via navigation component action with enter animation has been added. How to prevent views in Fragment B being clickable while enter animation is running? I've found this question How to add listener to android Navigation Architecture Component action animation but unfortunately there're no answers.

我在文档中发现的是,我可以通过钩在 NavAction 上的 NavOptions 对象获得该动画的资源ID,而不是通过 Animation 钩住code>对象本身.

What I found in the documentation is that I could get resource ID of that animation through NavOptions object hooked onto the NavAction, but not the Animation object itself.

推荐答案

您可以先在XML android:enabled ="false" 中禁用视图,然后在片段的 onViewCreated中禁用视图,您可以使用协程设置动画持续时间的 delay :

You can start by having your views as disabled in xml android:enabled="false" then in your fragment's onViewCreated you can set a delay with the animation duration using coroutines:

override fun onViewCreated(view: View, savedState: Bundle?) {
    super.onViewCreated(view, savedState)

    // Initialize views here. 


    lifecycleScope.launch {
        delay(resources.getInteger(R.integer.anim_duration).toLong())
        // Enable views here
        myView.isEnabled = true
    }
}

这篇关于在通过导航组件添加到动作的动画完成之前,防止单击视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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