Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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??

like image 493
Droid_Dev Avatar asked Jun 28 '12 06:06

Droid_Dev


1 Answers

For API 11 (Android 3.0.x) and above: you can use View.setX() and View.setY(). See API docs for details.

For all API versions: you could use RelativeLayout and RelativeLayout.Layout. Specifically by setting margins in fields inherited from ViewGroup.MarginLayoutParams. I guess it would go something like this:

RelativeLayout parentLayout = (RelativeLayout) findViewById(R.id.relative_layout);

LinearLayout newLayout = new LinearLayout(this); // or some other layout

RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
    // You can enter layout absolute dimensions here instead of 'wrap_content'.
    ViewGroup.LayoutParams.WRAP_CONTENT,
    ViewGroup.LayoutParams.WRAP_CONTENT);
// Set your X and Y position here for new layout.
layoutParams.setMargins(100 /*left*/, 200 /*top*/, 0 /*right*/, 0 /*bottom*/); 
parentLayout.addView(newLayout , layoutParams);
like image 125
vArDo Avatar answered Dec 13 '22 02:12

vArDo