热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

显示或隐藏Android软键盘时调整布局-AdjustthelayoutwhentheAndroidsoftkeyboardisshownorhidden

MygoalistoachievewhatmostmessagingappslikeFacebookmessenger,Viber,Whatsupdowhendis

My goal is to achieve what most messaging apps like Facebook messenger, Viber, What's up do when displaying an attachment sheet. If the Soft keyboard is visible and the user wants to attach something, the keyboard is hidden and the attachment sheet is presented in its place.

我的目标是实现大多数消息应用程序,如Facebook Messenger,Viber,显示附件表时的功能。如果软键盘可见并且用户想要附加某些东西,则隐藏键盘并将附件页显示在其位置。

In order to make this work, the layout changes should happen when the root view size changes. Otherwise, a graphical glitch occurs where my layout changes are applied shortly before keyboard is shown/hidden.

为了使其工作,布局更改应在根视图大小更改时发生。否则,在键盘显示/隐藏之前不久应用我的布局更改时会出现图形故障。

If I could change my layout the exact moment the keyboard is hidden, I could get it right. I have tried using onGlobalLayoutListener but without the desired outcome.

如果我可以在键盘被隐藏的确切时刻改变我的布局,我可以把它弄好。我尝试过使用onGlobalLayoutListener但没有达到预期的效果。

enter image description here

3 个解决方案

#1


0  

Add this line in the manifest of your activity.

在活动清单中添加此行。

 

#2


0  

Use this code It will be Helpful.

使用此代码这将是有帮助的。

android:windowSoftInputMode="adjustNothing"

#3


0  

The best place to find out whether your layout changed due to the keyboard (dis)appearing and acting on the change is inside onMeasure() of the root layout.

找出由于键盘(dis)出现并根据更改而更改布局的最佳位置是根布局的onMeasure()内部。

In more detail, I made a custom LinearLayout, which is used as my root layout. I overrided the onMeasure and I calculate what is the current keyboard height. Depending on the keyboard'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's height the same as the keyboard.

更详细地说,我做了一个自定义的LinearLayout,它用作我的根布局。我压倒了onMeasure,我计算出当前的键盘高度。根据键盘的高度以及我的附件网格是否可见,我更改了附件网格的可见性。我甚至可以将网格的高度设置为与键盘相同。

The results looks like the grid was always beneath the keyboard and the textview remains in the same vertical place.

结果看起来网格始终位于键盘下方,文本视图保持在同一垂直位置。


推荐阅读
author-avatar
易中天我最爱
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有