0

Bitte helfen Sie mir, eine Code-Kollision zwischen zwei ImageView in Android Studio. danke soviel
aber Kollision nicht erkannt wird, ist es nicht geschnitten immer bemerken, bitte helfen Sie mirKollision 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(); 
       } 
     } 

Antwort

0

versuchen mit

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

es elbe auch ist, immer noch nicht funktioniert –