0
Ich möchte nur eine Schaltfläche in Y-Richtung ziehen und ablegen. Ich habe diese Funktionalität erreicht. Aber es überschreitet Bildschirmgrenzen und ist verschwunden. Bitte helfen Sie mir, mein Ziel zu erreichen.Drag and Drop eine Taste?
Hier ist mein Code
public class ChoiceTouchListener implements View.OnTouchListener{
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
int x = (int) motionEvent.getRawX();
int y = (int) motionEvent.getRawY();
DisplayMetrics metrics = getResources().getDisplayMetrics();
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams tparams = (RelativeLayout.LayoutParams) view.getLayoutParams();
changey = y- tparams.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 params = (RelativeLayout.LayoutParams) view.getLayoutParams();
params.topMargin = y-changey;
view.setLayoutParams(params);
break;
}
rootlayout.invalidate();
return true;
}
}
Was ist "v" in Ihrem Code? – Hasnain
Ansichtsparameter von onTouch. Sie können den Code in onTouch schreiben und v durch Ansicht ersetzen – Anmol
in Ordnung. Lass mich diesen Code ausprobieren. – Hasnain