Другая проблема с imageView

Интерфейс, диалоги, темы, стили, меню
Ответить
AdinaS
Сообщения: 26
Зарегистрирован: 10 июл 2014, 20:01

Другая проблема с imageView

Сообщение AdinaS » 31 окт 2014, 17:43

Как сделать так чтобы textview увеличивался на 1 если imageview который выполняет animation и imageView сталкиваются или если animation доходит до места imageView который передвигается? Вот код, пока не работает.
Большое спасибо.

Код: Выделить всё

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;
  
  
}
}

Ответить