调整布局时,显示或隐藏Android的软键盘 [英] Adjust the layout when the Android soft keyboard is shown or hidden

查看:301
本文介绍了调整布局时,显示或隐藏Android的软键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是要实现大多数即时通讯应用,如Facebook的使者,Viber的,显示附件表时什么事做。如果软键盘是可见的,并且用户要附加的东西,键盘是隐藏的附件表是在其位psented $ P $。

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.

为了使这项工作,布局的变化应该发生在根视图大小改变时。否则,在应用我的布局变化显示前不久键盘/隐藏图形故障发生。

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.

如果我可以改变我的布局的确切时刻键盘被隐藏,我可以得到它的权利。我已经尝试使用 onGlobalLayoutListener 但不理想的结果。

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.

在这里输入的形象描述

推荐答案

要找出你的布局是否由于改变了键盘(DIS)最好的地方出现,并作用于改变是在 onMeasure( )根布局。

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.

在更多的细节,我做了一个自定义的LinearLayout,这是作为我的根布局。我overrided的 onMeasure 和<我一个href=\"https://github.com/DrKLO/Telegram/blob/2114024ab1d9cf209916bcdb3a4a7d44e51a3b0c/TMessagesProj/src/main/java/org/telegram/ui/Components/SizeNotifierFrameLayout.java#L65\"相对=nofollow>计算什么是当前的键盘高度。根据键盘的高度,是否我的执着格应该是可见或不可见,我更改附件网格的可见性。我甚至可以设置网格的高度一样的键盘。

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.

结果看起来像网格总是在键盘下方和TextView的保持在相同的垂直位置。

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

这篇关于调整布局时,显示或隐藏Android的软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆