1

当用户单击编辑文本时,我只想将我的整个活动屏幕向上移动...我的意思是屏幕将向上移动,在它下方我们可以看到软键盘...我尝试使用 android:windowSoftInputMode="adjustPan |adjustResize”在我的清单文件中,但它没有任何意义..提前谢谢...

4

1 回答 1

0

在您的 xml 布局中。使滚动视图成为根父级,它将起作用!

试试这个来检测键盘是否启动,然后向下滚动(你需要你的滚动是 xml 中的根):

final View activityRootView = findViewById(R.id.scroll);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
        //keyboard is visible
        if (heightDiff > 100) {
            scroll.fullScroll(ScrollView.FOCUS_DOWN);
        }
    }
});
于 2012-07-06T12:58:56.120 回答