0
我已經創建了在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
}
.......
何你在初始化'mainView'嗎? – Kiskae
@Kiskae更新了問題 –