Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageView and set position

Tags:

android

I have imageView in activity. How I can set position this imageView in my activity. I know how I can do this in xml file but I want to do this in activity, because I have onTouch method where I get coordinates where I clicked and I want to draw this images in this coordinates.

like image 812
edi233 Avatar asked Mar 29 '12 11:03

edi233


2 Answers

@edi233--

I think you can get touch x & y so that you can calculate top margin & left margin. I think (0,0) will be left top corner so if you touch (100,75) you need to set margins of image view to top - 75 & left to 100

LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

params.setMargins(100,75, 0,0);
// OR
params.topMargin= 100;

image.setLayoutParams(params);
like image 94
Sandip Jadhav Avatar answered Sep 30 '22 01:09

Sandip Jadhav


use the View.layout(int, int, int, int) in order to set its position

like image 29
Blackbelt Avatar answered Sep 30 '22 01:09

Blackbelt