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??
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With