简体   繁体   English

键盘打开时滚动到recyclerview中的位置

[英]Scroll to position in recyclerview when keyboard opens

Problem: 问题:

I have an edittext as a password field in a viewholder in a recyclerview . 我在recyclerview一个viewholder中有一个edittext作为密码字段。 If the user clicks on it, the keyboard will appear below it. 如果用户单击它,则键盘将显示在其下方。

键盘隐藏了textview的edittext密码字段

Below the password field is a textview that gives feedback if the password the user has entered is valid. 密码字段下方是一个textview ,如果用户输入的密码有效,它将给出反馈。 But this textview is not visible, because it is hidden because of the softkeyboard . 但是此textview不可见,因为由于softkeyboard ,它被隐藏了。 Only after closing the softkeyboard , it is visible and he will see if the password he entered is correct. 仅在关闭softkeyboard ,它才可见,并且他会看到他输入的密码是否正确。 带有现在可见的textview的edittext密码字段

Question: 题:

Is there a way to let the softkeyboard scroll below the textview when the edittext is clicked or is there another way to make the password feedback visible to the user? 单击edittext时,是否有办法让softkeyboard滚动到textview下方,还是有另一种方法使用户看到密码反馈?

I would just put it in a scrollview. 我只是将其放在滚动视图中。 Then add bottom padding to the height of the soft board 然后将底部填充添加到软板高度

In this case you have a recycler view. 在这种情况下,您有一个回收站视图。 There is a Nested scrollview but without seeing your code I cannot recommend it. 有一个嵌套的滚动视图,但是没有看到您的代码,我不建议您这样做。 You can also add padding to the recyclerviews last element with the passwords for the same effect. 您也可以使用密码向recyclerviews最后一个元素添加填充,以达到相同的效果。 But this design is starting to sound funky.. Maybe its time to break this into its own fragment / activity? 但是这种设计听起来似乎很时髦。也许是时候将其分解成自己的片段/活动了?

That said this SO looks like your solution 也就是说,这样看起来像您的解决方案

What you're looking for is the Activity's windowSoftInputMode attribute. 您正在寻找的是活动的windowSoftInputMode属性。 You set this in your AndroidManifest.xml file, and give it a value such as: 您可以在AndroidManifest.xml文件中进行设置,并为其提供一个值,例如:

adjustResize: "The activity's main window is always resized to make room for the soft keyboard on screen." AdjustResize:“活动的主窗口始终会调整大小,以便为屏幕上的软键盘腾出空间。”

adjustPan: "The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window." AdjustPan:“活动的主窗口没有调整大小以为软键盘腾出空间。相反,窗口的内容会自动平移,以便键盘永远不会遮挡当前焦点,并且用户始终可以看到他们在键入什么。这通常,“调整大小”不如“调整大小”理想,因为用户可能需要关闭软键盘才能到达窗口并与模糊的部分进行交互。” adjustResize will probably work for you, as long as you wrap the layout in a ScrollView. 只要将布局包装在ScrollView中,adjustResize可能就对您有用。 It may have negative effects if you have a bitmap image in the background, as it will be resized as well, in which case you may want to use adjustPan instead. 如果背景中有位图图像,则可能会产生负面影响,因为它也会被调整大小,在这种情况下,您可能要使用adjustPan。

or 要么

More information is available at the above link. 在上面的链接中可以找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM