Skip to content

Instantly share code, notes, and snippets.

@elqsar
Created February 28, 2014 19:44
Show Gist options
  • Save elqsar/9278343 to your computer and use it in GitHub Desktop.
Save elqsar/9278343 to your computer and use it in GitHub Desktop.
Scroll to top in ScrollView if softkeyboard visible
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final View rootView = getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int height = rootView.getRootView().getHeight() - rootView.getHeight();
if(height > 100) {
loginScrollView.post(new Runnable() {
@Override
public void run() {
loginScrollView.smoothScrollTo(0, loginScrollView.getBottom());
}
});
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment