我的目标是实现大多数消息应用程序,如Facebook Messenger,Viber,显示附件表时的功能 . 如果软键盘可见并且用户想要附加某些东西,则隐藏键盘并将附件页显示在其位置 .
为了使其工作,布局更改应在根视图大小更改时发生 . 否则,在显示/隐藏键盘之前不久应用布局更改的位置会出现图形 glitch .
如果我可以在键盘被隐藏的确切时刻改变我的布局,我可以把它弄好 . 我尝试过使用 onGlobalLayoutListener ,但没有达到预期的效果 .
onGlobalLayoutListener
在活动清单中添加此行 .
<activity android:name="com.your.Activity" android:windowSoftInputMode="stateHidden|adjustPan" />
使用此代码这将是有帮助的 .
android:windowSoftInputMode="adjustNothing"
找出由于键盘(dis)出现并根据更改而更改布局的最佳位置是根布局的 onMeasure() 内 .
onMeasure()
更详细地说,我做了一个自定义的LinearLayout,它用作我的根布局 . 我压倒了 onMeasure 和我calculate当前的键盘高度是多少 . 取决于键盘's height and whether my attachment grid should be visible or not, I change the visibility of the attachment grid. I can even set the grid'的高度与键盘相同 .
onMeasure
结果看起来网格始终位于键盘下方,文本视图保持在同一垂直位置 .
3 回答
在活动清单中添加此行 .
使用此代码这将是有帮助的 .
找出由于键盘(dis)出现并根据更改而更改布局的最佳位置是根布局的
onMeasure()
内 .更详细地说,我做了一个自定义的LinearLayout,它用作我的根布局 . 我压倒了
onMeasure
和我calculate当前的键盘高度是多少 . 取决于键盘's height and whether my attachment grid should be visible or not, I change the visibility of the attachment grid. I can even set the grid'的高度与键盘相同 .结果看起来网格始终位于键盘下方,文本视图保持在同一垂直位置 .