android making layout scrollable when soft keyboard open, but not shifting it upwards

前端 未结 9 1933
忘掉有多难
忘掉有多难 2020-12-18 19:16

This is my screen, with one button hidden behind the keyboard.

I want exactly like this, but scrollable. -

Whenever, the keyboard

相关标签:
9条回答
  • 2020-12-18 20:13

    Refer this to choose the appropriate mode for your screen https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

    0 讨论(0)
  • 2020-12-18 20:18

    If you want it to scroll (only when keyboard pop up), you will need adjustResize warped in scrollView, but adjustResize automatically shifted the page for you.

    may be you could scroll the page to the desired position after the adjustResize occur

    // this is the edittext
            this.setOnFocusChangeListener(new OnFocusChangeListener() {
    
                @Override
                public void onFocusChange(View view, boolean hasFocus) {
                    int[] absLocation = new int[2];
                    int absHeight = absLocation[1];
    
                    if (hasFocus) {
                            ScrollView sv = // get the id of your scroll view
    
                            if (sv != null){
                                view.postDelayed(new Runnable() {
    
                                    @Override
                                    public void run() {
                                        sv.smoothScrollBy(0, number); // how much you want to scroll to
                                    }
                                }, 700);  // some delay after the adjust Resize
    
                            }
                        }
                    }
                }
            });
        }
        ```
    
    
    0 讨论(0)
  • 2020-12-18 20:21

    I may be late to answer, but may help someone.

    I was also facing this issue and ended up hiding button which we don't want to be visible on keyboard up. So in this case it's "create account" which is to be hidden on keyboard up and show on keyboard down.

    0 讨论(0)
提交回复
热议问题