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

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

相关文档推荐

How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
cocos2d-android: how to display score(cocos2d-android:如何显示分数)
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
Android file copy(安卓文件拷贝)
Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)