繁体   English   中英

Android - EditText与Softkeyboard重叠

[英]Android - EditText overlap with Softkeyboard

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

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

关于如何避免它的任何建议?

我想你应该看看这个链接。 那个概率。 看起来非常类似于你的那个。

对我来说,我不想假设键盘高度是一定的测量值。 无论您关注什么视图制作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);
        }



    });

//基本上我们制作一个可运行的滚动到某个视图的新位置,你想在屏幕上看到它。 只有当它不在scrollviews范围内(它不在屏幕上)时才执行该runnable。 这样它就会将scrollview转换为引用的视图(在我的情况下,'someview'是一个行分隔符)。

暂无
暂无

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

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