Collision imageView
Добавлено: 04 ноя 2014, 19:05
У меня есть 2 картинки, одна с анимацией translate а другую можно передвигать по оси x по экрану. Я хочу чтобы когда они сталкиваются textView показывал count++ а если не сталкиваются count--. Долго искала в интернете, но ничего не сработало. Вот мой код
Спасибо 
Код: Выделить всё
public class Level1Activity extends Activity implements OnTouchListener {
private int _xDelta;
private int _yDelta;
TextView tv;
float x,y,m,n;
int count;
private int width;
private int height;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView img_animation = (ImageView) findViewById(R.id.img_animation);
Animation anim = null;
anim = AnimationUtils.loadAnimation(this, R.anim.translate);
img_animation.startAnimation(anim);
ImageView j = (ImageView)findViewById(R.id.imageView);
TextView tv = (TextView) findViewById(R.id.tv);
j.setOnTouchListener(this);
}
public boolean onTouch(View view, MotionEvent event) {
final int X = (int) event.getRawX();
ImageView img_animation = (ImageView) findViewById(R.id.img_animation);
ImageView j = (ImageView)findViewById(R.id.imageView);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
_xDelta = (int) (X - j.getTranslationX());
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
j.setTranslationX(X - _xDelta);
break;
}
return true;
}
}