我试图滚动到特定点时的EditText用户点击,从而增加了以下code听单击并专注于此的EditText:
I try to scroll to specific point when the user click on edittext, so added the following code to listen to click and focus on this edittext:
et_email = (EditText) view.findViewById(R.id.editEmail);
//bring to center of screen when clicked / focused
et_email.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ScrollView scrollView = (ScrollView)getView().findViewById(R.id.ScrollViewSendDetails);
scrollView.smoothScrollTo(0, 500);
}
});
et_email.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
ScrollView scrollView = (ScrollView) getView().findViewById(R.id.ScrollViewSendDetails);
scrollView.smoothScrollTo(0, 500);
}
});
问题是,滚动只有第二次点击后的作品。在关于什么的EditText第一次点击情况
The problem is that the scrolling works only after the second click. In the first click on the edittext nothing happens
为什么你要监听器一样吗?尝试使用onTouch监听器:
Why do you have to listener for the same? Try to use an onTouch listener:
et_email.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEvent.ACTION_DOWN == event.getAction()) {
ScrollView scrollView = (ScrollView)getView().findViewById(R.id.ScrollViewSendDetails);
scrollView.smoothScrollTo(0, 500);
}
return false;
}
});