views:

120

answers:

1

I've been struggling for a few days on this, finally just decided to ask. It's so simple I've got to be missing something very basic.

I have an XML layout page with an image defined. I have two anim XML pages, one to change alpha from 0 to 1, and the other from 1 to 0 in order to create a "blinking" effect. So the alphaAnimation is defined in XML, I just need to call it.

The image pops up, but there's no looping blinking effect.

public class blinker extends Activity {

   //create name of animation
Animation myFadeInAnimation;
Animation myFadeOutAnimation;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.scanning_view);

 //grab the imageview and load the animations
    ImageView myImageView = (ImageView) findViewById(R.id.blinkingView01); 
    Animation myFadeInAnimation = AnimationUtils.loadAnimation(null, R.anim.fade_in);
    Animation myFadeOutAnimation = AnimationUtils.loadAnimation(null, R.anim.fade_out);

//fade it in, and fade it out. 
    myImageView.startAnimation(myFadeInAnimation);
    myImageView.startAnimation(myFadeOutAnimation);
     }
}   

Two XML Animation layouts in Anim resource:

<?xml version="1.0" encoding="UTF-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"&gt; 
    <alpha android:fromAlpha="0.0" 
    android:toAlpha="1.0" 
    android:interpolator="@android:anim/accelerate_interpolator"  
    android:duration="50" android:repeatCount="infinite"/> 
 </set> 

And the other:

 <?xml version="1.0" encoding="UTF-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"&gt; 
    <alpha android:fromAlpha="1.0" android:toAlpha="0.0" 
    android:interpolator="@android:anim/accelerate_interpolator"  
    android:duration="1000" android:repeatCount="infinite"/> 
</set>
A: 

Why not use android:repeatMode="reverse"

methodin
Still same issue. Screen appears, but no animation.
Keith
Why is your first parameter null instead of this in: nimationUtils.loadAnimation(null,... ?
methodin
that was yet another iteration, I've been through so many, including another complete rewrite to animate the image. Originally I stipulated "this".
Keith
I needed a break to rest sore eyes. I implemented two things after reading through responses Methodin, and I have it working now. Many thanks.
Keith
Excellent. Glad to help!
methodin
Methodin, too many hours at the screen and keyboard. :) The iteration aboved worked when I went back to "this". I decided not to use repeatMode="reverse" just so I could have more granualar control over the fade in and fade out speeds since each can be set independently of each other. Fast fade in, slow fade out by example.
Keith