2013-02-22 3 views
27
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.vitesse); 

    gpsManager = new GPSManager(); 

    gpsManager.startListening(getApplicationContext()); 
    gpsManager.setGPSCallback(this); 
    Typeface tf = Typeface.createFromAsset(getAssets(), 
      "font/DS-DIGI.TTF"); 
    TextView loding =(TextView)findViewById(R.id.info_message); 
      loding.setTypeface(tf); 
      AlphaAnimation fadeIn = new AlphaAnimation(0.0f , 1.0f) ; 
      AlphaAnimation fadeOut = new AlphaAnimation(1.0f , 0.0f) ; 
      loding.startAnimation(fadeIn); 
      loding.startAnimation(fadeOut); 
      fadeIn.setDuration(500); 
      fadeOut.setDuration(1200); 
      fadeOut.setStartOffset(1200+fadeIn.getStartOffset()+1200);  
      measurement_index = AppSettings.getMeasureUnit(this); 
} 

Ich möchte diese von Textview Loding Animation wiederholen, bis gotting eine inforamtion von GPSRepeat android Animation

Antwort

71

Wie this.

animation.setRepeatCount(Animation.INFINITE); 
+0

danken alex es funktioniert gut :) – EMIN

+0

Cheers, es ist üblich, obwohl eine richtige Antwort zu akzeptieren. – alex

5
fadeIn.setRepeatCount(int count) 

fadeIn.setRepeatMode(AlphaAnimation.INFINITE(or any other repeat mode reletaed yo your usage)) 

können Sie diese Methoden wiederholen steuern.

diese implementieren, wenn

//anim = your animation 


anim.setAnimationListener(new AnimationListener() 
     { 

      public void onAnimationStart(Animation arg0) 
      { 
       // TODO Auto-generated method stub 

      } 


      public void onAnimationRepeat(Animation arg0) 
      { 
       // TODO Auto-generated method stub 

      } 

      public void onAnimationEnd(Animation arg0) 
      { 


      } 
     }); 

benötigt, wenn Sie suddennly stoppen Ihre Animation wollen. Verwenden Sie yourview.clearAnimation() Ich hoffe, das hilft.

+0

[setRepeatMode] (http://developer.android.com/reference/android/view/animation/Animation.html#setRepeatMode (int)) erwartet nur RESTART oder REVERSE. INFINITE sollte nur an setRepeatCount übergeben werden. –

10

Sie könnten dies tun

animation.setRepeatCount(Animation.INFINITE); //Repeats animation indefinitely. 
+0

Funktioniert für mich. Einfach und effektiv – Bundeeteddee

8

Android Sie elegante Mechanismen gibt den Ladevorgang zu repräsentieren. Sie können eine unbestimmte ProgressBar oder eine ImageView mit einer Skala/Alpha-Animation verwenden, anstatt die TextView selbst zu animieren.

Vielleicht finden Sie diese Animation nützlich, um Alpha und Skala gleichzeitig zu animieren. Variieren Sie die Parameter für Ihre Präferenz:

file R.anim.alpha_scale_animation

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 
<scale 
    android:fromXScale="0.7" 
    android:toXScale="1.0" 
    android:fromYScale="0.7" 
    android:toYScale="1.0" 
    android:pivotX="50%p" 
    android:pivotY="50%p" 
    android:duration="4000" 
    android:repeatCount="infinite" 
    /> 

<alpha 
    android:fromAlpha="0.0" 
    android:toAlpha="1.0" 
    android:duration="2000" 
    android:repeatMode="reverse" 
    android:repeatCount="infinite" 
    /> 
</set> 

dann in Ihrem Code zu starten:

Animation connectingAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.alpha_scale_animation); 
myView.startAnimation(connectingAnimation); 

Und um es zu stoppen:

myView.clearAnimation(); 
connectingAnimation.cancel(); 
connectingAnimation.reset(); 

Sie auch verwenden können Bibliotheken wie ProgressButtonView, um Benutzerinteraktion und Ladenprozess zu unterstützen, i n das gleiche Widget.

Hoffnung, dass jeder dieser Lösungen jemand brauchbares Ergebnis :)

+0

Nice one thanks – Sam