scrollTo焦点后/ onClick事件后,才第二次点击作品 [英] scrollTo after focus/onClick event works only after second click

查看:484
本文介绍了scrollTo焦点后/ onClick事件后,才第二次点击作品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这篇关于scrollTo焦点后/ onClick事件后,才第二次点击作品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆