将 EditText 定位在键盘上方

Positioning EditText Above Keyboard(将 EditText 定位在键盘上方)
本文介绍了将 EditText 定位在键盘上方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 EditText 看起来像这样(带有底部重力"):

I have got an EditText looking like this (with "bottom gravity"):

当我按下 EditText 时,键盘会出现,我无法再看到我正在输入的内容(因为 EditText 现在位于键盘后面,位于底部).按下键盘后,如何将 EditText 自动移动到键盘上方?

When I press the EditText, the keyboard shows up and I can't see anymore what I'm typing (because the EditText is now behind the keyboard, on the bottom). How could I move the EditText automatically just above the keyboard, when it has been pressed?

最后,如果它看起来像这样就好了:

At the end, it would be good if it would look like this:

我的代码:

// LINEAR LAYOUT
LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setOrientation(LinearLayout.VERTICAL);
setContentView(layout);
// TEXTVIEW
layout.addView(tv);
// EDITTEXT
et.setGravity(Gravity.BOTTOM);
et.setInputType(InputType.TYPE_CLASS_TEXT);
et.setImeOptions(EditorInfo.IME_ACTION_SEND);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
                        params.gravity = Gravity.BOTTOM;
                        et.setLayoutParams(params); // SOMETHING LIKE ONTOUCH -> MOVE UPWARDS
                        layout.addView(et);

推荐答案

在您的 Manifest 文件中为这个特定活动添加以下代码

In your Manifest file add the following code for this particular activity

<activity android:windowSoftInputMode="adjustPan">

查看此文档了解更多信息.

Check this doc for more info.

这篇关于将 EditText 定位在键盘上方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Prevent enter key on EditText but still show the text as multi-line(防止在 EditText 上输入键,但仍将文本显示为多行)
Android keyboard next button issue on EditText(EditText上的Android键盘下一个按钮问题)
When the soft keyboard appears, it makes my EditText field lose focus(当软键盘出现时,它使我的 EditText 字段失去焦点)
android how to make text in an edittext exactly fixed lines(android如何在edittext中制作文本完全固定的行)
How to use regular expression in Android(如何在 Android 中使用正则表达式)
Filter list view from edit text(从编辑文本中过滤列表视图)