Domanda

I want to make a ProgressDialog for my app that used flashes an image while resources are loaded in the background. I've looked at a number of questions on StackOverflow that deal with creating indeterminate animation, mostly circular. However, I can't seem to find any information on how to make a flashing progress dialog with a static image. I realize that I can define the animation in XML but how do I control the timing of the image and more importantly, how can I add fade in and fade out ?

È stato utile?

Soluzione

As you've probably already found out you'll have to create a custom dialog: http://developer.android.com/guide/topics/ui/dialogs.html

In this dialog you will have your image. You will also need an animation file similar (but not exact) to this:

    <?xml version="1.0" encoding="UTF-8"?> 
    <set xmlns:android="http://schemas.android.com/apk/res/android"> 
        <alpha 
        android:fromAlpha="0.0" 
        android:toAlpha="0.6"  
        android:duration="2000"/> 
    </set> 

You can change the duration as well set something like a 'repeatCount'.

Then in your code you will enable the animation on the image as such:

    body =(ImageView)this.findViewById(R.id.myView);
    Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadeid);
    body.startAnimation(myFadeInAnimation);

So, you can control the timing with 'duration' and 'repeatCount'. Then you can control the fading in and out by setting the 'toAlpha' and 'fromAlpha'.

Of course, this is pseudocode and not exactly what you need to do...but hopefully its enough to get you started...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top