ImageView的,并设置位置 [英] ImageView and set position

查看:96
本文介绍了ImageView的,并设置位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在活动ImageView的。如何设置这个位置中的ImageView我的活动。我知道我可以在XML文件中做到这一点,但我想这样做的活动,因为我有onTouch方法,其中我得到我的地方点击坐标,我想在这个坐标绘制这个图像。

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.

推荐答案

@ edi233--

@edi233--

我觉得你可以触摸X'放大器; Ÿ这样就可以计算上边距和放大器;左边距。我认为,(0,0)将在左上角,所以如果你触摸(100,75),你需要图像视图距设置顶部 - 75安培;留给100

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);

这篇关于ImageView的,并设置位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆