拖放的TextView [英] drag and drop textview
问题描述
我要拖我不能够完美地将它拖到: 这些问题是: 1)我不得不拖动两至三次,以使该所希望position.Hence TextView的不继手指移动顺畅。 2)如果我在向上移动的TextView它只会向下。
我预先提供的TextView触摸event.Please help.Thanks的code。
最后的TextView T =(TextView中)findViewById(R.id.textView4);
t.setOnTouchListener(新OnTouchListener(){
公共布尔onTouch(视图V,MotionEvent我){
// TODO自动生成方法存根
浮X = me.getX();
浮动Y = me.getY();
如果(me.getAction()== MotionEvent.ACTION_DOWN){
状态= START_DRAGGING;
}
如果(me.getAction()== MotionEvent.ACTION_UP){
状态= STOP_DRAGGING;
t.setPadding((int)的me.getX(),(int)的me.getY(),10,10);
Log.i(拖,停止拖动);
}如果(me.getAction()== MotionEvent.ACTION_MOVE){
如果(状态== START_DRAGGING){
的System.out.println(拖);
t.setPadding((int)的me.getX(),(int)的me.getY(),10,10);
t.invalidate();
}
}返回true;
}});
也许你的不动查看
就是他们都应该的,在Android上的方法吗?
setPadding()
不是去它的最佳途径。
下面是拖的另一种方式和Drop 以查看
取值
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.
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;
}});
Perhaps you are not moving View
s the way they are supposed to, in Android?
setPadding()
is not the best way to go about it.
Here is an alternative way of Drag and Drop for View
s
这篇关于拖放的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!