Android - EditText 与软键盘重叠

发布于 2024-10-20 16:10:33 字数 229 浏览 1 评论 0原文

我正在开发一个有一些 EditText 的 Activity。当我单击/触摸 EditText 时,会出现软键盘。但是屏幕底部的 EditText 与软键盘重叠。显示 EditText 的上半部分,下半部分位于键盘下方。

我在 AndroidManifest.xml 中设置了 android:windowSoftInputMode="adjustPan"

关于如何避免它有什么建议吗?

I am working on an Activity which have some EditText. When I click/touch on EditText softkeyboard appear. But the EditTexts which are at bottom of the screen, overlap with softkeyboard. Upper half of the EditText is shown and lower half is under the keyboard.

I set the android:windowSoftInputMode="adjustPan" in AndroidManifest.xml

Any Suggestion about how to avoid it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人爱我别走 2024-10-27 16:10:33

对我来说,我不想假设键盘高度是一定的尺寸。无论您关心什么视图,都创建一个 onTouchListener,然后执行以下操作:

    setOnTouchListener(new OnTouchListener()  {



        Runnable shifter=new Runnable(){
            public void run(){
                try {
                    int[] loc = new int[2];                 
                    //get the location of someview which gets stored in loc array
                    findViewById(R.id.someview).getLocationInWindow(loc);
                    //shift so user can see someview
                    myscrollView.scrollTo(loc[0], loc[1]);   
                }
                catch (Exception e) {
                    e.printStackTrace();
                }   
            }}
        };

        Rect scrollBounds = new Rect();
        View divider=findViewById(R.id.someview);
        myscollView.getHitRect(scrollBounds);
        if (!divider.getLocalVisibleRect(scrollBounds))  {
            // the divider view is NOT  within the visible scroll window thus we need to scroll a bit.
            myscollView.postDelayed(shifter, 500);
        }



    });

// 本质上,我们创建一个可运行的对象,滚动到您希望在屏幕上可见的某个视图的新位置。仅当该可运行程序不在滚动视图范围内(不在屏幕上)时才执行该可运行程序。这样,它将滚动视图转移到引用的视图(在我的例子中是“someview”,它是一个行分隔符)。

For me i did not want to assume that keyboards heights are a certain measurement. Whatever view your concerned about make a onTouchListener and then do this:

    setOnTouchListener(new OnTouchListener()  {



        Runnable shifter=new Runnable(){
            public void run(){
                try {
                    int[] loc = new int[2];                 
                    //get the location of someview which gets stored in loc array
                    findViewById(R.id.someview).getLocationInWindow(loc);
                    //shift so user can see someview
                    myscrollView.scrollTo(loc[0], loc[1]);   
                }
                catch (Exception e) {
                    e.printStackTrace();
                }   
            }}
        };

        Rect scrollBounds = new Rect();
        View divider=findViewById(R.id.someview);
        myscollView.getHitRect(scrollBounds);
        if (!divider.getLocalVisibleRect(scrollBounds))  {
            // the divider view is NOT  within the visible scroll window thus we need to scroll a bit.
            myscollView.postDelayed(shifter, 500);
        }



    });

//essentially we make a runnable that scrolls to a new location of some view that you WANT visible on the screen. you execute that runnable only if its not within the scrollviews bounds (its not on the screen). This way it shifts the scrollview to the referenced view (in my case 'someview' which was a line divider).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文