Android - adjust scrollview when keyboard is up fo

2019-01-26 11:19发布

I have a problem on android lollipop, screen doesn't adjust size when the softkeyboard comes up.

This is my manifest intro example from one of the activity i made:

android:windowSoftInputMode="stateAlwaysHidden|adjustResize" 

Is there something new that is added and we have to take into account for android 5.0 ? The scrollview works fine on android < 5.0.

3条回答
来,给爷笑一个
2楼-- · 2019-01-26 11:35

For the guy's who still have this issue even with android:fitsSystemWindows="true" in the ScrollView.

I found few ways to solve it:

  1. use as root fragment.xml layout RelativeLayour and put android:fitsSystemWindows="true" inside. ScrollView use as a child of RelativeLayour.
<RelativeLayout android:fitsSystemWindows="true">
  <ScrollView/>
</RelativeLayout>
  1. use NestedScrollView instead of ScrollView.

Both options should be used with android:windowSoftInputMode="adjustResize" and works on Android 5 with <item name="android:windowTranslucentStatus">true</item> flag. `

查看更多
神经病院院长
3楼-- · 2019-01-26 11:38

the problem was that it didn't work with translucent status bar and i had to set

 android:fitsSystemWindows="true"

in my main layout

查看更多
Deceive 欺骗
4楼-- · 2019-01-26 11:56

Nothing I've tried has worked and Ive gone through every single concievable combination of different Manifest settings etc to no avail.

Its a little hacky but it works beautifully for me:

((RelativeLayout) findViewById(R.id.rootLayout)).addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                scrollToLatest(); // Do your scrolling!
            }
        });
查看更多
登录 后发表回答