简体   繁体   English

Android - EditText与Softkeyboard重叠

[英]Android - EditText overlap with Softkeyboard

I am working on an Activity which have some EditText. 我正在开发一个有一些EditText的Activity。 When I click/touch on EditText softkeyboard appear. 当我单击/触摸EditText软键盘时出现。 But the EditTexts which are at bottom of the screen, overlap with softkeyboard. 但位于屏幕底部的EditTexts与软键盘重叠。 Upper half of the EditText is shown and lower half is under the keyboard. 显示EditText的上半部分,下半部分位于键盘下方。

I set the android:windowSoftInputMode="adjustPan" in AndroidManifest.xml 我在AndroidManifest.xml中设置了android:windowSoftInputMode="adjustPan"

Any Suggestion about how to avoid it? 关于如何避免它的任何建议?

i think you should look at this link. 我想你应该看看这个链接。 that prob. 那个概率。 seems very similar to the one you have. 看起来非常类似于你的那个。

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: 无论您关注什么视图制作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);
        }



    });

//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). 只有当它不在scrollviews范围内(它不在屏幕上)时才执行该runnable。 This way it shifts the scrollview to the referenced view (in my case 'someview' which was a line divider). 这样它就会将scrollview转换为引用的视图(在我的情况下,'someview'是一个行分隔符)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM