使用手势后,EditText无法编辑

时间:2012-08-24 14:39:28

标签: android android-edittext

我创建了一个edittext,它可以在触摸时移动,键盘可以在双击或长按时打开。它工作得很好,但我面临两个问题:

  1. EditText可以从最后一个文本或从文本开始编辑。我无法选择光标的位置。

  2. 拖动编辑文字&从左角落下而不是从中心落下。

  3. 触摸侦听器的代码是:

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
    
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) v.getLayoutParams();
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                setEnabled(true);
                setCursorVisible(true);
    
                break;
    
            case MotionEvent.ACTION_UP:
                Log.d("up", "ACTION_UP");
                params.height = LayoutParams.WRAP_CONTENT;
                params.width = LayoutParams.WRAP_CONTENT;
                params.topMargin = (int)(event.getRawY() - (v.getHeight()/2));
                params.leftMargin = (int)(event.getRawX() - (v.getWidth()/2));
                txt_metaData.Xmargin= params.topMargin;
                txt_metaData.YMargin= params.leftMargin;
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d("moving", "ACTION_MOVE");
    
                params.topMargin = (int)(event.getRawY() - (v.getHeight()/2));
                params.leftMargin = (int)(event.getRawX() - (v.getWidth()/2));
                v.setLayoutParams(params);
                break;
        }
        return gestureScanner.onTouchEvent(event);
    }
    
    @Override
    public boolean onDown(MotionEvent e)
    {   
        return true;
    }
    
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
    {
        return true;
    }
    @Override
    public void onLongPress(MotionEvent e)
    {
        Log.i("double tap called", "yes");
        ((InputMethodManager)_mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
        setEnabled(true);
        requestFocus();
        requestFocusFromTouch();
    }
            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
            {
                return true;
            }
    
            @Override
            public void onShowPress(MotionEvent e)
            {
    
    
            }    
            @Override
            public boolean onSingleTapUp(MotionEvent e)    
            {
                return true;
            }
            @Override
            public boolean onDoubleTap(MotionEvent e) 
            {
                Log.i("double tap called", "No");
                 ((InputMethodManager)_mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                    setEnabled(true);
                    requestFocus();
                    requestFocusFromTouch();
                 return true;
            }
            @Override
            public boolean onDoubleTapEvent(MotionEvent e) 
            {
                 return true;
            }
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) 
            {
                bringToFront();
                return true;
            }
        }
    

0 个答案:

没有答案