How to disable the move threshold when getting touch events?
It's called touch slop. And here's the same question already answered: Android ACTION_MOVE Threshold
android: move a view on touch move (ACTION_MOVE)
Something like this:
public class MyActivity extends Activity implements View.OnTouchListener {
TextView _view;
ViewGroup _root;
private int _xDelta;
private int _yDelta;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_root = (ViewGroup)findViewById(R.id.root);
_view = new TextView(this);
_view.setText("TextView!!!!!!!!");
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(150, 50);
layoutParams.leftMargin = 50;
layoutParams.topMargin = 50;
layoutParams.bottomMargin = -250;
layoutParams.rightMargin = -250;
_view.setLayoutParams(layoutParams);
_view.setOnTouchListener(this);
_root.addView(_view);
}
public boolean onTouch(View view, MotionEvent event) {
final int X = (int) event.getRawX();
final int Y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
_xDelta = X - lParams.leftMargin;
_yDelta = Y - lParams.topMargin;
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
layoutParams.leftMargin = X - _xDelta;
layoutParams.topMargin = Y - _yDelta;
layoutParams.rightMargin = -250;
layoutParams.bottomMargin = -250;
view.setLayoutParams(layoutParams);
break;
}
_root.invalidate();
return true;
}}
In main.xml
just RelativeLayout
with @+id/root
Related Topics
How to Update UI from Asynctask
The Specified Child Already Has a Parent. You Must Call Removeview() on the Child's Parent First
Firebase Token Authentication Error
Getactionview() of My Menuitem Return Null
Android Httpclient:Networkonmainthreadexception
Failure [Install_Failed_Already_Exists] When I Tried to Update My Application
Why Isn't My Vector Drawable Scaling as Expected
How to Use Roboto Font in Android Project
Configure Eclipse to Use Signed Keystore
Android Opening a File with Action_Get_Content Results into Different Uri'S
Multiple Dex Files Define Lcom/Google/Android/Gms/Internal/Zzau
What Are the Overheads of Using Autoincrement for SQLite on Android
Cordova Platform Add Android Not Working While Listing Android Targets