scrollTo焦点后/ onClick事件后,才第二次点击作品事件、焦点、作品、scrollTo

2023-09-06 23:50:34 作者:逗逼你为何那么逗!

我试图滚动到特定点时的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;
        }
    });
 
精彩推荐