When user click on edittext I want the screen to scroll to show the edittext in the middle of the screen. So I tried to listen to touch (setOnTouchListener, also tried with onClick and onFocuse) and then smoothScrollTo screen to put the edittext in the middle of the screen.
but for some reason when I add the setOnTouchListener to the edittext it doesn't get focus at all.
what do I need to fix? or how can I achieve this?
this is the setOnTouchListener code that cause the edittext not to get focused when clicked:
et_email.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
ScrollView scrollView = (ScrollView)getView().findViewById(R.id.ScrollViewSendDetails);
scrollView.smoothScrollTo(0, et_email.getBottom());
return true;
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…