软输入平移视图,但不足以显示完整的 editText
我有一个有点复杂的布局,但在最底部是一个巨大的 EditText。当我点击它打开键盘时,所有内容都会向上滑动,足以准确显示用户正在键入的位置(当用户开始键入时,只有 1 行可见,如果用户转到多行,则它会平移更多一点)显示 2 行等)。我希望所有内容都平移,以便整个 EditText (所有空白区域)可见。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical">
<EditText
android:id="@+id/CommentBox"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:textSize="16sp"
android:layout_marginLeft="6dp"
android:layout_marginTop="4dp"
android:background="@color/transparent"
android:textColor="@color/gray"
android:gravity="top"
android:inputType="textMultiLine|textCapSentences|textShortMessage|textAutoCorrect|textNoSuggestions">
</EditText>
</LinearLayout>
这几天一直在努力解决这个问题,非常感谢任何建议。
最好的说明方法是使用 3 个图像
这是整个屏幕的样子
这是现在的行为是什么
这是所需的行为
希望这些图像能说明我的问题。我需要弄清楚如何实现这一点。我能够强制视图平移到正确位置的唯一方法是将 android:gravity 设置为 Bottom ,在这种情况下,文本会写在底部。然而,这显然是一种非常奇怪的用户体验。我需要像普通文本框中的文本一样。
I have a somewhat complicated layout, but at the very bottom is a huge EditText. When I click on it to get the keyboard to open, everything slides up just enough to show exactly where the user is typing (as the user begins typing only 1 line is visible, if the user goes to multiple lines then it pans a little more to show 2 lines, etc). I would like everything to pan so that the whole EditText (all the blank space) is visible.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical">
<EditText
android:id="@+id/CommentBox"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:textSize="16sp"
android:layout_marginLeft="6dp"
android:layout_marginTop="4dp"
android:background="@color/transparent"
android:textColor="@color/gray"
android:gravity="top"
android:inputType="textMultiLine|textCapSentences|textShortMessage|textAutoCorrect|textNoSuggestions">
</EditText>
</LinearLayout>
Been struggling with this for a couple days now, would appreciate any suggestions.
Best way to illustrate is with 3 images
This is what the entire screen looks like
This is what the behavior is right now
This is the desired behavior
Hopefully the images illustrate my question. I need to figure out how to make this happen. The only way I have been able to force view to pan to the right place is by setting, android:gravity to bottom , in which case text is written at the bottom. This however, is clearly a very weird user experience. I need text to be like in a normal text box.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
能够拼凑出一个模仿我正在寻找的解决方案。
将布局放在scrollView中,将参数设置为adjustResize而不是adjustPan。单击编辑文本时,我
很想找到一种非黑客方法来做到这一点,但这就是我所拥有的。
Was able to hack together a solution that mimics what I was looking for.
Put the layout inside a scrollView, set the parameter to adjustResize instead of adjustPan. And on click in the editText did
Would love to find a non-hacky way to do this, but this is all I've got.