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


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)