我必须拖动,但无法完美拖动它:
问题是:
1)我必须拖动两到三次才能将其带到所需的位置。因此 textview 不能顺利跟随手指移动。
2)如果我向上移动文本视图,它只会向下移动。
我提供了触摸事件上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;
}});
也许你是没有移动View这是他们应该做的 http://developer.android.com/guide/topics/ui/drag-drop.html,在安卓中?
setPadding()
这不是最好的方法。
Here 是拖放的另一种方式 http://blahti.wordpress.com/2011/01/17/moving-views-part-2/ for View
s
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)