将 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 定位在键盘上方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:将 EditText 定位在键盘上方

基础教程推荐