Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeat android animation

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

I want to repeat this of textview loding animation until gotting an inforamtion from GPS

like image 540
EMIN Avatar asked Feb 22 '13 09:02

EMIN


People also ask

Is animation possible on Android?

On Android 4.4 (API level 19) and higher, you can use the transition framework to create animations when you swap the layout within the current activity or fragment. All you need to do is specify the starting and ending layout, and what type of animation you want to use.

What is fillAfter in Android?

android:fillAfterWhen set to true, the animation transformation is applied after the animation is over. The default value is false. If fillEnabled is not set to true and the animation is not set on a View, fillAfter is assumed to be true.


2 Answers

Like this.

animation.setRepeatCount(Animation.INFINITE); 
like image 168
alex Avatar answered Oct 13 '22 05:10

alex


Android gives you elegant mechanisms to represent the loading process. You could use an indeterminate ProgressBar, or an ImageView with a scale/alpha animation, instead of animating the TextView itself.

Maybe you might find this animation useful, for animating alpha and scale at the same time. Vary the parameters for your preference:

file res/anim/alpha_scale_animation.xml

<?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> 

then to launch it in your code:

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

And to stop it:

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

You can also use libraries like ProgressButtonView to have both user interaction and loading process supported in the same widget.

Hope that any of these solutions result useful to someone :)

like image 22
voghDev Avatar answered Oct 13 '22 05:10

voghDev