2016-06-02 7 views
-1

Abbrechen Ich habe meinen Code hier und mein Problem ist, dass ich nur eine bestimmte Animation aktiv haben möchte, wenn eine If-Bedingung erfüllt ist. Sie können über meinen Code sehen, dass ich dafür alle anderen Animationen separat schließen muss, um mein Ziel zu erreichen.Wie alle Animationen außer einem bestimmten in Android Studio

Ich möchte wissen, ob dies ein sauberer Weg ist.

 beaconManager = new BeaconManager(this); 
     beaconManager.setBackgroundScanPeriod(2000,20000); 
     beaconManager.setRangingListener(new BeaconManager.RangingListener() { 
      @Override 

      public void onBeaconsDiscovered(Region region, List<Beacon> list) { 
       if (!list.isEmpty()) { 
        Beacon nearestBeacon = list.get(0); 
        int number = nearestBeacon.getMajor(); 

        if(number == 1479) 
        { 
         Animation an = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.test); 
         blueButton.startAnimation(an); 
         yellowButton.clearAnimation(); 
         blueButton2.clearAnimation(); 
         orangeButton.clearAnimation(); 
         orangeButton2.clearAnimation(); 
         purpleButton.clearAnimation(); 
         redButton.clearAnimation(); 
         greenButton.clearAnimation(); 


        } 

        if(number == 7574) 
        { 
         Animation an = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.test); 
         blueButton2.startAnimation(an); 
         blueButton.clearAnimation(); 
         yellowButton.clearAnimation(); 
         orangeButton.clearAnimation(); 
         orangeButton2.clearAnimation(); 
         purpleButton.clearAnimation(); 
         redButton.clearAnimation(); 
         greenButton.clearAnimation(); 


        } 
        . 
        . 
        . 
        if(number == 61120) 
       { 
        Animation an = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.test); 
        yellowButton.startAnimation(an); 
        blueButton.clearAnimation(); 
        blueButton2.clearAnimation(); 
        orangeButton.clearAnimation(); 
        orangeButton2.clearAnimation(); 
        purpleButton.clearAnimation(); 
        redButton.clearAnimation(); 
        greenButton.clearAnimation(); 
       } 



      } 
     } 
    }); 
    region = new Region("ranged region", null, null, null); 
} 

Antwort

0

Sie können auch anim.cancel() anrufen; aber Sie sollten auch anim.reset(); sofort danach anrufen. Wenn Sie es dann erneut starten möchten, rufen Sie startAnimation in der Ansicht auf.

+0

Vielen Dank für Ihre Antwort, aber leider funktioniert das nicht. Ich habe das auch schon mal ausprobiert, aber die Sache ist, wenn ich startAnimation nach anim.cancel() und anim.reset() wieder einsetze, zeigt mein Programm nicht nur meine gewünschte Animation, sondern alle Animationen, die ich vorher zusammen benutzt habe :) – Andrew

Verwandte Themen