Tag: motionevent

使用MotionEvent在视图上同时移动两个位图

我使用下面的类(Android中的简单2D图形)在我的视图上创建了两个位图,并且漫游以实现该位图可以独立移动。 我为此调用了motionevent方法。 目前的问题,我不明白为什么在下面的代码中只有一个对象正在移动。 例如,使用此代码,只移动“not”位图,我想独立于彼此移动两个位图。 scenrio:我可以使用我的两个fingures,每个对象一个,独立移动位图。 但我不知道如何实现这一目标。 public class TouchView extends View { private Drawable cross; private Rect crossBounds = null; private Drawable not; private Rect notBounds = null; private int x1, y1, x2, y2 ; boolean flag = true; private void intialize () { int w1 = cross.getIntrinsicWidth(); int h1 = cross.getIntrinsicHeight(); x1 = 100; […]

如何通过拖放将图像保留在布局中

我有以下XML: 这在我的Android手机中提供了以下图像 我如何编码,以便用户可以将图像拖动到布局中的任何位置, ImageView将始终保持在布局中? 如果X<0则为X =(X + imageview.width()) 如果Y<0则为Y =(Y + imageview.height()) 如果X>layout.width()它将是X =(X-imageview.width()) 如果Y>layout.height() ,它将是Y =(Y-imageview.height())? 与此类似的东西: 因此,如果用户拖动视图外,方形图像将保留在FrameLayout中的最后一个已知位置 我将布局背景转换为位图,以便我可以使用它来获取X和Y坐标并转换为我的应用程序的RGB值。 f = (FrameLayout) findViewById(R.id.fl); f.setOnTouchListener(flt); iv = (ImageView) findViewById(R.id.iv); f.setDrawingCacheEnabled(true); f.buildDrawingCache(); bm = f.getDrawingCache(); 我有以下代码可以工作,但每隔一段时间我得到一个错误NPE for x must be <= layout.width()或y must be <= layout.height(); 。 有时应用程序允许我拖动布局本身的右侧或底部,这不应该发生,因为我有条件不允许它。 @Override public boolean onTouch(View v, MotionEvent event) { […]