Alex Rivera | Logout

Adding a child in a GestureOverlayView on the point where i touched in android?

Asked 2012-06-28T06:31:54.507
10

How can i add a child(a layout) in a gestureoverlayview at the point where i touched in that view..... Is it possible to position it according to the co ordinates of the location??

Edit
Report

1 Answer

0
public boolean onTouchEvent(MotionEvent event) {
    TextView tv=new TextView(this);

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        x = event.getX();
        y = event.getY();
        RelativeLayout gh = (RelativeLayout) findViewById(R.id.relative1);
        RelativeLayout.LayoutParams para = new RelativeLayout.LayoutParams(150, 50); //Size of textView
        para.leftMargin = (int) x;  //location of textview
        para.topMargin = (int) y;
        tv.setLayoutParams(para);

        tv.setText("You have Touched at  "+x+" ,"+y);
        change();
        gh.addView(tv);
    }
answered 2012-08-20T18:19:14.673

Your Answer