ScrollView中的editText被InputKeyboard隐藏的问题



Hej,

我有一个editText供用户输入他的位置,它位于ScrollView中。当用户点击它时,我希望滚动视图滚动到editText字段的正下方,键盘也会出现。

现在我得到的是:

EditText是隐藏的

设置滚动视图的代码部分是:

final int[] location = {0, 0};
final int[] locationScroll = {0, 0};
keywordsedittext.getLocationInWindow(location);
mainScroll.getLocationInWindow(locationScroll);
float px = Utils.pixelsFromDP(keywordsedittext.getPaddingTop(), PropertyMainMenuActivity.this);
location[1] = (int) (location[1] - locationScroll[1] - px);
mainScroll.smoothScrollTo(0, location[1]);
((LockableScrollView) mainScroll).setScrollingEnabled(false);
keywordsedittext.setFocusable(true);
keywordsedittext.requestFocusFromTouch();
InputMethodManager lManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
lManager.showSoftInput(keywordsedittext, 0);

因此,基本上滚动视图滚动到editText的Y高度坐标(删除了顶部填充(。但是当代码被执行时,editText的输入文本区域会被键盘输入隐藏起来。

我该如何处理这个问题?

在清单中使用此选项

<activity android:windowSoftInputMode="adjustPan"> </activity>

adjustPan移动页面内容而不调整其大小

了解更多信息https://developer.android.com/guide/topics/manifest/activity-element

将其添加到您的ScrollView xml:

android:fillViewport="true"

将其添加到Manifest.xml 中

android:windowSoftInputMode="adjustResize"

你应该很乐意去。

最新更新