无法在分离的视图上启动动画师
我已经创建了在Kotlin中扩展PopupView的类,并尝试使用CircleReveal库进行动画显示。 这是我班的功能
fun show(root: View) { showAtLocation(root, Gravity.CENTER, 0, 0) val cx = (mainView.left + mainView.right) / 2 val cy = (mainView.top + mainView.bottom) / 2 val dx = Math.max(cx, mainView.width - cx) val dy = Math.max(cy, mainView.height - cy) val finalRadius = Math.hypot(dx.toDouble(), dy.toDouble()).toFloat() with (ViewAnimationUtils.createCircularReveal(mainView, cx, cy, 0f, finalRadius)) { interpolator = AccelerateDecelerateInterpolator() duration = 1500 start() } }
该代码给我下面的错误
java.lang.IllegalStateException: Cannot start this animator on a detached view! at android.view.RenderNode.addAnimator(RenderNode.java:817) at android.view.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:300) at android.view.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:282) at android.animation.RevealAnimator.<init>(RevealAnimator.java:37) at android.view.ViewAnimationUtils.createCircularReveal(ViewAnimationUtils.java:53) at io.codetail.animation.ViewAnimationUtils.createCircularReveal(ViewAnimationUtils.java:74) at io.codetail.animation.ViewAnimationUtils.createCircularReveal(ViewAnimationUtils.java:39)
类初始化
class MemberMenu(ctx: Context, val member: Member): PopupWindow(ctx), View.OnClickListener { val mainView: View init { contentView = LayoutInflater.from(ctx).inflate(R.layout.member_menu_layout, null) mainView = contentView.findViewById(R.id.member_menu_view) val size = Helpers.dipToPixels(ctx, 240f) width = size; height = size setBackgroundDrawable(ColorDrawable()) isOutsideTouchable = true isTouchable = true } .......
不知道,如果这是正确的解决方案,但我只是将该代码移动到OnAttachStateChangeListener
fun show(root: View) { showAtLocation(root, Gravity.CENTER, 0, 0) backgroundView.addOnAttachStateChangeListener(this) } override fun onViewAttachedToWindow(v: View?) { if (v==null) return with(ViewAnimationUtils.createCircularReveal(v, 500, 500, 0f, 500f)) { interpolator = AccelerateDecelerateInterpolator() duration = 2500 start() } } override fun onViewDetachedFromWindow(v: View?) {}
- 反序列化包含数组的Firestore文档的推荐方法是什么?
- 在android java类中使用Kotlin扩展
- 一堆在android studio中使用kotlin的错误
- 使用编译“org.jetbrains.kotlin:kotlin-stdlib-jre7:$ kotlin_version”给错误
- 无法在Android Studio中切换到调试版本变体
- 无法获得SupportMapFragment返回任何东西…似乎总是为空
- 在Kotlin支持棒棒糖
- 错误:com.app.android.dagger.component.AppComponent(unscoped)可能不引用作用域绑定:
- Kotlin的原始类型属性不允许使用lateinit修饰符