【问题标题】:drag and drop textview拖放文本视图
【发布时间】:2011-12-02 11:41:05
【问题描述】:

我必须拖动,但无法完美拖动: 问题是: 1)我必须拖动两到三次才能将其带到所需的位置。因此 textview 不能顺利地跟随手指移动。 2)如果我向上移动 textview 它只会向下移动。

我正在提供有关触摸事件的 textview 代码。请帮助。提前致谢。

 final TextView t=(TextView)findViewById(R.id.textView4);
           t.setOnTouchListener(new OnTouchListener(){

            public boolean onTouch(View v, MotionEvent me) {
                    // TODO Auto-generated method stub
                float x = me.getX();
                float y = me.getY();

                if (me.getAction() == MotionEvent.ACTION_DOWN) {
                    status = START_DRAGGING;
                }
                if (me.getAction() == MotionEvent.ACTION_UP) {
                    status = STOP_DRAGGING;
                    t.setPadding((int) me.getX(), (int) me.getY(), 10, 10);

                    Log.i("Drag", "Stopped Dragging");
                }  if (me.getAction() == MotionEvent.ACTION_MOVE) {
                    if (status == START_DRAGGING) {
                        System.out.println("Dragging");

                        t.setPadding((int) me.getX(), (int) me.getY(), 10, 10);

                        t.invalidate();
                    }
                }return true;
            }}); 

【问题讨论】:

  • 您是在模拟器上还是在实际手机上遇到此问题?因为模拟器很慢,所以它可以解释为什么你必须多次这样做。

标签: android drag-and-drop


【解决方案1】:

也许你是not moving Views the way they are supposed to,在Android 中?

setPadding() 不是最好的方法。


这里是is an alternative way of Drag and DropViews

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多