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

前端 未结 9 1950
忘掉有多难
忘掉有多难 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: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
    
                            }
                        }
                    }
                }
            });
        }
        ```
    
    

提交回复
热议问题