Большое спасибо.
Код: Выделить всё
public class MainActivity extends Activity implements OnTouchListener {
private int _xDelta;
private int _yDelta;
TextView tv;
int count;
@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 img_animation1 = (ImageView) findViewById(R.id.img_animation1);
Animation anim1 = null;
anim1 = AnimationUtils.loadAnimation(this, R.anim.translate);
img_animation1.startAnimation(anim1);
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());
if(j.getLayoutParams() == img_animation.getLayoutParams()){
tv.setText("Score" + count++);
}else {
tv.setText("Score" + count--);
}
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);
if(j.getLayoutParams() == img_animation.getLayoutParams()){
tv.setText("Score" + count++);
}else {
tv.setText("Score" + count--);
}
break;
}
return true;
}
}