【发布时间】:2014-03-03 21:22:42
【问题描述】:
我正在尝试动态地重新定位视图(其中包含画布元素)。这个想法是让用户触摸盒子并能够在屏幕上拖动它。我打算抓住 touch motion_events 以重新定位用户拖动的块。这是我目前拥有的代码,我认为它可以工作,但到目前为止还没有产生任何成功。
int[] coords = getLastLocations();
setContentView(R.layout.activity_main);
View mainv = findViewById(R.id.mainRelativeLayout);
BoxView bvr = (BoxView) findViewById(R.id.BoxViewRed);
BoxView bvb = (BoxView) findViewById(R.id.BoxViewBlue);
bvr.setColor(255, 0, 0);
bvr.layout(coords[0], coords[1], 60, 60);
bvb.setColor(0, 0, 255);
bvb.layout(coords[2], coords[3], 60, 60);
mainv.invalidate();
任何有关如何使此代码工作的提示或其他方法都是完美的。
附:针对 ICS+ (API 14-19)
【问题讨论】:
-
@Daniel,这似乎是个不错的方法,有时间我会尝试并更新帖子。
-
好的,很高兴你试一试