我在活动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的,并设置位置
发布评论