Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid : Move 2 Balls or more with Touch
    primarykey
    data
    text
    <p>Objective is to draw 2 points or more and segment line between those points. Then, we can move them by touch.</p> <p>Can't succeed in moving by touch, 2 balls or more, on a FrameLayout or other.</p> <p>Here are my java files.</p> <pre><code>public class GraphActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_graph); FrameLayout main = (FrameLayout)findViewById(R.id.main_view); main.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent e) { if (e.getAction() == MotionEvent.ACTION_DOWN) { float x = e.getX(); float y = e.getY(); ((FrameLayout)v).addView( new Ball(((FrameLayout)v).getContext(),x,y,20)); } return false; } }); } } </code></pre> <p>I'm adding balls on the layout. It works !</p> <p>Here is the java for the Ball.</p> <pre><code>public class Ball extends View { private float x; private float y; private int r; private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); public Ball(Context context, float x, float y, int r) { super(context); mPaint.setColor(0xFFFF0000); this.x = x; this.y = y; this.r = r; this.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent e) { if (e.getAction() == MotionEvent.ACTION_MOVE) { v.setX(e.getX()); v.setY(e.getY()); return true; } return false; } }); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(x, y, r, mPaint); } } </code></pre> <p>Trying many other combination on MotionEvent actions... can't guess where i lost understanding View or Motion.</p> <p>Thanks for help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload