【问题标题】:Android - EditText overlap with SoftkeyboardAndroid - EditText 与软键盘重叠
【发布时间】:2011-03-06 10:15:06
【问题描述】:

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

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

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

【问题讨论】:

    标签: android android-edittext


    【解决方案1】:

    对我来说,我不想假设键盘高度是一定的测量值。无论您关注什么观点,都可以创建一个 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' 是一个行分隔符)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      • 2023-03-29
      • 2014-10-19
      • 1970-01-01
      相关资源
      最近更新 更多