Android - adjust scrollview when keyboard is up for android 5.0 (lollipop)

拟墨画扇 提交于 2019-11-29 10:23:00

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

 android:fitsSystemWindows="true"

in my main layout

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. `

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!
            }
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!