拖放文本视图 [英] drag and drop textview
本文介绍了拖放文本视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须拖动,但无法完美拖动:问题是:1)我必须拖动两到三次才能将其带到所需的位置.因此 textview 不能顺利地跟随手指移动.2)如果我向上移动 textview 它只会向下移动.
I have to drag and i am not able to drag it perfectly: The issues are: 1) I have to drag two to three times to bring that to desired position.Hence textview is not following the finger movement smoothly. 2)If i move textview in upward direction its only going downwards.
我正在提供有关触摸事件的 textview 代码.请帮助.提前致谢.
I am providing the code of textview on touch event.Please help.Thanks in advance.
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 中没有按照应有的方式移动 View
?
setPadding()
不是最好的方法.
这里 是拖放的另一种方式 for 查看
s
这篇关于拖放文本视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文