android - 出现键盘时向上滚动屏幕

标签 android scroll android-edittext keyboard android-scrollview

I have an activity with an editText in the middle. When I click on the editText the keyboard appears, and the screen moves so that the editText is just above the keyboard, covering the other stuff that is below.

I don't want to resize or add padding to the layout. I need that the screen scrolls to the top the amount of space that I need to see also the other stuff below. In other words, I'd like to select the position of the editText when the keyboard appears. It would be enough also if the screen scrolls up completely, showing me the bottom of the layout.

我试图将布局放在 ScrollView 中,在 editText 上添加此代码

    editText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //make the view scroll down to the bottom
            scrollView.scrollTo(0, scrollView.getBottom());

        }
    });

但它不起作用。有人有想法吗?提前谢谢!

最佳答案

使用 android:windowSoftInputMode="adjustPan"

“调整大小”

Activity 的主窗口总是会调整大小,以便为屏幕上的软键盘腾出空间。

“调整盘”

Activity 的主窗口没有调整大小来为软键盘腾出空间。相反,窗口的内容会自动平移,因此当前焦点永远不会被键盘遮挡,用户始终可以看到他们正在输入的内容。这通常不如调整大小可取,因为用户可能需要关闭软键盘才能到达窗口的模糊部分并与之交互。

例如 inn 你的 list 文件:-

       <activity
    android:windowSoftInputMode="adjustPan"
    android:name=".MainActivity"></activity>

迟到的答案。但肯定对任何人都有帮助。

关于android - 出现键盘时向上滚动屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19554939/

相关文章:

android - fragment 之间的动画过渡 - 滑动效果 - 半透明的statusBar和ActionBar

android - 在解析依赖关系之前复制文件以构建 Android 应用程序

CSS:只滚动到可见内容

jQuery 触摸可拖动响应滚动条/幻灯片/轮播?

Android - 软键盘将我的 Activity 布局推到屏幕外

android - EditText 显示 2 行文本,而不是 1 行,尽管设置了所有属性(仅在 Galax Tab 10.1,ICS 上)

java - 保存 webview 内容以供离线浏览?

jquery - 如何判断滚动 Pane 在 JavaScript 中滚动的方式?

Android EditText - 只允许一个小数点分隔符

android - 扩展 MediaRouteButton 行为