0

アンドロイドスタジオの2つのImageViewの間でコードの衝突を助けてください。 はそんなに
に感謝するが、それは衝突を検出していない、それは常に交差しない気づく、私を助けてくださいcollision ImageView in android studio

protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      setContentView(R.layout.activity_second);        


      int x = img_animation.getRight() - img_animation.getLeft(); 
      int y = img_animation.getBottom() - img_animation.getTop(); 
      final TranslateAnimation translate = new TranslateAnimation(
        Animation.ABSOLUTE, x, Animation.ABSOLUTE, 
        2000, Animation.ABSOLUTE, 0, 
        Animation.ABSOLUTE, y); 
      translate.setDuration(3200);//speed of the animation 
      translate.setFillEnabled(true); 
      translate.setFillAfter(true); 
      img_animation.startAnimation(translate); 

    //2nd brick animation 

      int x1 = img_animation1.getRight() - img_animation1.getLeft(); 
      int y1 = img_animation1.getBottom() - img_animation1.getTop(); 
      final TranslateAnimation secondone = new TranslateAnimation(
        Animation.ABSOLUTE, x1, Animation.ABSOLUTE, 
        -2000, Animation.ABSOLUTE, 0, 
        Animation.ABSOLUTE, y1); 
      secondone.setDuration(5200);//speed of the animation 
      secondone.setFillEnabled(true); 
      secondone.setFillAfter(true); 
      img_animation1.startAnimation(secondone); 

       Rect R1=new Rect(img_animation.getLeft(), img_animation.getTop(),img_animation.getRight(),img_animation.getBottom()); 
       img_animation.getHitRect(R1); 
       Rect R2=new Rect(img_animation1.getLeft(),img_animation1.getTop(),img_animation1.getRight(),img_animation1.getBottom()); 
       img_animation1.getHitRect(R2); 

       if (Rect.intersects(R1, R2)) { 

        Toast.makeText(this, "Intersected!", Toast.LENGTH_SHORT).show(); 
       } else { 

        Toast.makeText(this, "Not Intersected!", Toast.LENGTH_SHORT).show(); 
       } 
     } 

答えて

0

は、それはまだ動作していない、あまりにも同じである

int x = img_animation.getX(); 
int y = img_animation.getY(); 
+0

てみてください –