在键盘上方放置EditText [英] Positioning EditText Above Keyboard
本文介绍了在键盘上方放置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);
推荐答案
在清单文件中,为此特定活动添加以下代码
In your Manifest file add the following code for this particular activity
<activity android:windowSoftInputMode="adjustPan">
查看此文档以获取更多信息.
Check this doc for more info.
这篇关于在键盘上方放置EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文