键盘向上时在视图中添加边距

问题描述

我想在margin 上升下降时更改button的{​​{1}},但是我遇到了问题我在下面描述它。

我在keyboard中实现了keyboard listener

baseFragment()

我像这样在我的fun softKeyboardListener(softKeyBoard: SoftKeyBoardListener) { rootView_phoneInput.viewTreeObserver .addOnGlobalLayoutListener { val heightDiff = rootView_phoneInput.rootView.height - rootView_phoneInput.height if (heightDiff > mScreenUtil.dpToPx( DEFAULT_DP_SIZE_SCREEN ) ) softKeyBoard.isKeyboardUp(true) else softKeyBoard.isKeyboardUp(false) } } 中使用它:

Fragment

它可以工作,但是在调试时遇到问题: override fun initUiListener() { softKeyboardListener(object :SoftKeyBoardListener{ override fun isKeyboardUp(isUp: Boolean) { if (isUp)button_phoneInput_logIn.setMargin(bottom = 0)//First line else button_phoneInput_logIn.setMargin(bottom = 32)//Second line } }) } 中的softKeyboardListener()进入了第一行第二行间的循环>(我向他们评论)在逻辑上是真的。

我的问题是如何防止这种情况发生?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)